Skip to main content

Java StringTokenizer trouble ... help!

1 reply [Last post]
ShawneeNDN
Offline
Joined: 2006-02-17
Points: 0

Howdy,

I'm having a problem with the StringTokenizer ...

The input i am supplying is:
Oklahoma City, OK: 12:24

And the output i want is:
12:24 Oklahoma City OK

But for the outputs, all i'm getting is:
12 Oklahoma City OK

My question is ... how do i make it so that the token doesnt end at the : inbetween 12 and 24, but so that it ends after the 24??

here is the code i'm using...

StringTokenizer tok = new StringTokenizer(firstLineFinal);
String city = tok.nextToken(",");
String state = tok.nextToken(", :");
String time = tok.nextToken(": \n");
System.out.println(time + " " + city + " " + state);

Thanks in advance...
-Nick

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zander
Offline
Joined: 2003-06-13
Points: 0

FIrst of all; these forums are about javaDesktop, and this issue is a general Java topic which does not belong here.

The stirng tokenizer indeed has a bad JavaDoc; what the method (nextToken) actually does is that it takes any char in the string as a delimiter.
The stringTokenizer is incapable of delimiting on more then one char.

I suggest you use a RegExp.