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

StringTokenizer

 
Kalyani Nayak
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic