• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

singing the substring blues

 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the situation:
I have a text file sitting on my unix with the following text:

name Eric
email eric@ericbarnhill.com
subject test
comment test

now I read this file with an applet and it tokenizes it into:

nameString = "name Eric"
emailString = "email eric@ericbarnhill.com"
subjectString = "subject test"
commentString = "comment test"

that works ok, I checked it. now I want to parse this data and take off the labels so I can redisplay it. I write this code:

parsedName = nameString.substring(5);
parsedEmail = emailString.substring(6);
parsedSubject = subjectString.substring(8);
parsedComment = commentString.substring(8);

my plan is that I would get the four strings "Eric", "eric@ericbarnhill.com", "test", "test". But it's not working out that way. I get "me Eric", "il eric@ericbarnhill.com", "ect test" and "ent test".
Thanks for reading my long post! Anyone know what I'm missing here?
Thanks
Eric
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Barnhill:
Here's the situation:
I have a text file sitting on my unix with the following text:

name Eric
email eric@ericbarnhill.com
subject test
comment test

now I read this file with an applet and it tokenizes it into:

nameString = "name Eric"
emailString = "email eric@ericbarnhill.com"
subjectString = "subject test"
commentString = "comment test"

that works ok, I checked it. now I want to parse this data and take off the labels so I can redisplay it. I write this code:

parsedName = nameString.substring(5);
parsedEmail = emailString.substring(6);
parsedSubject = subjectString.substring(8);
parsedComment = commentString.substring(8);

my plan is that I would get the four strings "Eric", "eric@ericbarnhill.com", "test", "test". But it's not working out that way. I get "me Eric", "il eric@ericbarnhill.com", "ect test" and "ent test".
Thanks for reading my long post! Anyone know what I'm missing here?
Thanks
Eric


It looks like the lines are padded with some non-pritable characters in front. Do a length() on each and see if this might not be the case. If it is and the number is consistant, add these into your consideration. However, you might want to consider using StringTokenizer on each and getting the last element.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic