aspose file tools*
The moose likes Beginning Java and the fly likes Stupid question: parsing a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stupid question: parsing a string" Watch "Stupid question: parsing a string" New topic
Author

Stupid question: parsing a string

Ben Roy
Ranch Hand

Joined: Nov 01, 2000
Posts: 70
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

Joined: Oct 31, 2000
Posts: 241
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

Joined: Sep 29, 2000
Posts: 8521
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?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ben Roy
Ranch Hand

Joined: Nov 01, 2000
Posts: 70
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stupid question: parsing a string