Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stupid question: parsing a string

 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, easy question. I have a string like: "apples;oranges;bananas;" Is there a better way to get this into an array than just readChar() and look for ";"? Or is that the preferred method? Enlightenment please!
 
Art Metzer
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll definitely want to investigate java.util.StringTokenizer, Ben.
Here's a little sample code:

Instead of printing out the tokens one by one, you can build your array there. Method countTokens() will come in handy when you initialize your array.
HTH
Art.
[This message has been edited by Art Metzer (edited February 05, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben, Ben, Ben,
There are NO stupid questions. And this is a GOOD question. Without you asking such things, how would I ever keep learning?
 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, I know. But it just seemed like the sort of thing I should already know. There are just some things that you feel a little silly when you realize you don't know how to do, or at least not what you consider a good way. Thanks for the tip, btw, it's exactly what I was looking for.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic