We help IT Professionals succeed at work.

How can i use StringTokenizer to break a string containing single quote?

Zuzzi2
Zuzzi2 asked
on
Hi, May I know how come this does not work?

  StringTokenizer st = new StringTokenizer("java's guide", "\'");

How come this does not break the string into two tokens?
How can i get "java" and "s guide" out?
Comment
Watch Question

I can't tell, but do you have a space in your tokens?  It should look like this:

StringTokenizer st = new StringTokenizer("java's guide"," \'");

Please note the additional space in your token list.
Software Engineer
CERTIFIED EXPERT
Commented:
It does, here is an example that demonstrates.

import java.io.*;
import java.text.*;
import java.util.*;

public class Test {
     
     public static void main(String[] args) {
          StringTokenizer st = new StringTokenizer("java's guide", "\'");
          while (st.hasMoreTokens()) {
               System.out.println(st.nextToken());
          }
     }
}
Oops...sorry.  I misread your original question.  Knight is correct.  It works fine.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for knight00

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.