I am using String Tokenizer in my program to separate strings.
Delimiter I am trying to use is “);”. But I found out that StringTokenizer uses ) and ; as 2 different delimiters.
But I want to use it as combined.
How can I do it?
my code:
StringTokenizer st = new StringTokenizer(str,");");
String temp[] = new String[st.countTokens()];
while(st.hasMoreTokens()) {
temp[i]=st.nextToken();
i++;
}
Thanks
As many of the answers have suggested, String.split() will solve your problem. To escape the specific sequence you’re trying to tokenize on you will have to escape the ‘)’ in your sequence like this: