Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringTokenizer class

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
Hi,

may I know whether I can set the delimiters for the StringTokenizer to null and "," at the same time? If possible, may I know how to write the codee?

Thanks,
Janet
 
You want to set the delimeter to null ? You do realise what null is - a null pointer in memory - ie, a pointer to an address in memory that does not actually hold anything.

Your question does not make programmatical sense ...

--------------------------------------------------
Free Database Connection Pooling Software
 
When you say null, maybe you mean a character which ASCII value 0?

In which case, the constructor for the StringTokenizer takes a String for ther delimiters to use, so try:-
Code:
StringTokenizer t = new StringTokenizer("your string", "\u0000,");
 
If you want to set multiple delimiters, you can use the String.split method, which is recommended as a replacement for a StringTokenizer in any event. split() takes a regular expression as its delimiter, so you can split on commas and null bytes something like this:
Code:
String[] splitString = str.split( "[,\\0]" );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top