Posted By:
Stephen_Ostermiller
Posted On:
Monday, February 14, 2005 03:15 AM
StringTokenizer only does single character delimiters. It takes a string of single characters to use as delimiters as its argument. When you say "$$" you are actually saying, "Use $ as a delimiter, oh and use $ as delimiter". Not exactly what you mean. The second $ is completely redundant.
There are a couple things you can do. If you have Java 1.4 or later you can use the String.split method.
// Escape $ because it has special meaning in regular expressions.
String[] tokens = "This$$is$a test".split("\$\$");
If you are still using 1.3 or you want something a little more efficient you can use my StringHelper class. It has a split method that does not use regular expressions:
String[] tokens = com.Ostermiller.util.StringHelper.split("This$$is$a test", "$$") ;