Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem reading String  RSS feed

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a really stupid problem reading a String but I don't know how to solve it. The thing is that I have a string in the format:
"word1 ## word2 ## word3"
And I want to have in separate variables those words so I've built a function to get them (I know I colud use Scanner funcitions but I need this project to work on java 1.4) So my code is:


And the problem I've got is that it never exits the while(cadena.ready()) condition, I've tried doing a c = read() and then put while(c != -1), but it doesn't work either. It seems the read function never finds the end of the string. If anyone has a better way of doing it, I'll also appreciate it. Thanks a lot.
[ October 31, 2005: Message edited by: Emili Calonge ]
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
linia.split(" ## ") ?
 
Grant Gainey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're doing waaay too much work. Take a look at String.split(). It should do what you need.

Grant
 
Grant Gainey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Spoor:
linia.split(" ## ") ?

I knew I shouldn't have taken the time to write a test program!

Grant
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew it had to exist something like this, thank you so much. I have to say I had read all the api's on StringReader and things like this, all except the String api... I'm so good at searching .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!