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

StringTokenizer Issue

Swati Singhal
Ranch Hand

Joined: Dec 08, 2003
Posts: 31
Hi,

I have a String in which there are 5 tokens taht are delimited by tabs ("\t"). I was using the StringTokenizer to parse this line and get individual tokens.
It worked fine, till I encountered a situation where there were 2 tabs (instead of 1).
Now, since StringTokenizer doesn't return me an empty string, how can I find out if there is a consecutive occurrence of that token. I know that the 3rd constructor of String Tokenizer has a boolean argument that can be set true, but it doesn't seem to be doing good to me!!

Please help ASAP!!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Moved from SCJP.

"Swats" while you are waiting for a response to your problem, please review our JavaRanch Naming Policy, and change your displayed name to conform with it.

Thanks
[ January 18, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Instead of the legacy StringTokenizer (see API) why not use String.split?

Example:
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Swats",
I'm going to take a stronger stance than Barry.

Looking back through your history, it appears that you have changed your display name and it is now invalid. We rarely allow accounts with invalid display names to survive past 20 posts. Please change your display name immediately, or your account may be deleted without warning.

Dave.
Swati Singhal
Ranch Hand

Joined: Dec 08, 2003
Posts: 31
Hi Barry,

Even split() doesn't give me an empty string"" or a null if there are two tabs in succession. What I want is, that if there are 2 consecutive tabs, then it should be able to detect that and give me an empty String or null which occurs between the two consecutive tabs.
Swati Singhal
Ranch Hand

Joined: Dec 08, 2003
Posts: 31
Hi Barry,

It does work.
Thanks for the reply.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
There is an optional boolean parameter on StringTokenizer that will give you the delmiters as well as the tokens. With that turned on you might get

The logic to walk through these is a bit tougher than the split technique, but it might be useful if you're stuck on an older JVM one day.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: StringTokenizer Issue