My point was that given the problem of breaking a string into two: command + message, it just seems a long way around the bush to use a StringTokenizer and break the string into tokens, then rebuild it after extracting the first token. What I would do is this:
<pre>
// given String str = "command This is a message"
String s = str.trim();
int pos = s.indexof(" ");
String command = s.substring(0, pos-1);
String message = s.substring(pos+1);
</pre>
no loops, no concatenation, no new StringTokenizer(), just straightforward string extraction. If it were required to analyze and act on each token in str, then a StringTokenizer() would be appropriate, but with the problem as described, it's overkill IMO.
J.Lacar
Originally posted by Mark Savory:
JUNILU,
We're talking about parsing a delimited String into substrings. Why not reuse StringTokenizer for this? If you think you can improve on the way StringTokenizer does this, maybe you can create a new reusable class that we all can use.
[This message has been edited by JUNILU LACAR (edited March 07, 2001).]