Forums Register Login

StringTokenizer

+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1190 times.
Similar Threads
Command Parsing
Selection of Origin , destination or both
StringTokenizer and the "" empty string
String Tokenizer
Displaying individual text
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:28:44.