| Author |
Problem in StringTokenizer
|
Meet Gaurav
Ranch Hand
Joined: Oct 08, 2008
Posts: 492
|
|
Am trying to split the String as (^) Separeted. Even I tryed Split method also..Any Other Way to split this one.. Please assist Me I seen the String Tokenizer class they were charAt method for searching. This may be a reason for my problem. Regular Expression is the only Option [ November 03, 2008: Message edited by: Meet Gaurav ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Look closely at what you are separating on; you are getting exactly what you have requested. And please use String#split rather than StringTokenizer, as explained in the API.
|
 |
Meet Gaurav
Ranch Hand
Joined: Oct 08, 2008
Posts: 492
|
|
HI Campbell Ritchie, I was not able to split the string using Split(). Could you please assist me with the above example. I want (^) separated
|
 |
Meet Gaurav
Ranch Hand
Joined: Oct 08, 2008
Posts: 492
|
|
I tryed and finally I got this.. For the above example the beloew code splits the string to (^) separeated.. String delimeter = "\\(\\^\\)"; temp = str.split(delimeter); for(int i =0; i < temp.length ; i++) System.out.println(temp[i]);
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Sorry, I was confused about what you wanted to split on. But using StringTokenizer, if you look through the constructor details, it appears to use any part of the delimiter to split. So it can split on ( or ) or ^ or (^ or ^) or (^). You have found out (well done ) how to get the whole pattern into a regular expression.
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
Thanks for posting your solution for others to share!
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
Meet Gaurav
Ranch Hand
Joined: Oct 08, 2008
Posts: 492
|
|
how to get the whole pattern into a regular expression. ??? Am not getting this one.. This is my actual Code to split the strings to "(^)" separated ( - Special Character. So i need to add "/". And the slash is also a special character. so I need to add 1 more "/". And thats it. String[] temp = str.split("\\(\\^\\)"); for(int i =0; i < temp.length ; i++) System.out.println(temp[i]);
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
|
I'm not sure what your question is here? The pattern you have provided is correct.
|
 |
 |
|
|
subject: Problem in StringTokenizer
|
|
|