aspose file tools*
The moose likes Beginning Java and the fly likes StringTokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringTokenizer" Watch "StringTokenizer" New topic
Author

StringTokenizer

Kalyani Nayak
Greenhorn

Joined: Jan 01, 2006
Posts: 25
It is very surprising but I faced one problem using StringTokenizer class.
I used 2 parameter constructor i.e. StringTokenizer("This is my : first token ::: This is my : second token",":::");
Now in above case if I tokenize the string it gives me 4 tokens as

This is my
first token
This is my
second token

Instead it should give me

This is my : first token
This is my : second token

I am confused why it is tokenizing for single ':' as my seperator token is ':::'

Any body has idea ?
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Hi,
I'm also puzzled i tried the same thing with some thing like this



And my output turned out to be
This is my
b first token
c This is my
dj second token

May be the delim matches the first occurence .Anyways I would do this with String Split or regex

Regards,
Srikkanth.M
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3454
    
  12
The second parameter is a list of characters to use as delimiters, not a String to be used as a delimiter.

The String.split method is probably better for what you want to do.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringTokenizer