Computer Science Canada a method/class that finds commas |
Author: | krishon [ Sat Dec 06, 2003 12:23 pm ] |
Post subject: | a method/class that finds commas |
i'm doin io stuff now....i have read in lines and break stuff up where there are commas. I remember my teacher telling me there is some class or method or somethin that detects the instance of a comma, does anyone know what it is? thx |
Author: | Dan [ Sun Dec 07, 2003 1:22 am ] | ||
Post subject: | |||
i whould do somting like
not shure if that works 100%, dont have java comaipering instaled right on this comp. if it dose not wrok check spelling and may be mess with indexes of for loop and string. |
Author: | rizzix [ Sun Dec 07, 2003 1:36 am ] |
Post subject: | |
there is one class, although i haven't used it so i can't give u much help there, but i know its does something similar: http://java.sun.com/j2se/1.4.2/docs/api/index.html |
Author: | krishon [ Sun Dec 07, 2003 11:01 am ] |
Post subject: | |
yah...i've looked at the api but i dunno where it is. urs just goes to the beginning of the api. that's because its all frames and stuff....so could u just post like wut to click...e.g. java.lang>>string etc. thx |
Author: | rizzix [ Sun Dec 07, 2003 7:35 pm ] |
Post subject: | |
woops... heh http://java.sun.com/j2se/1.4.2/docs/api/java/io/StreamTokenizer.html |
Author: | krishon [ Sun Dec 07, 2003 7:40 pm ] |
Post subject: | |
THAT'S THE ONE...just dunno which method, lol |
Author: | yuethomas [ Mon Dec 08, 2003 9:30 pm ] | ||||||
Post subject: | |||||||
Depending on your needs, either StringTokenizer or StreamTokenizer will satisfy you. If you've already read the contents of your input file (you mentioned you were doing I/O) into a string, then you should put it through StringTokenizer to generate tokens. However, if you want to streamline the process and just parse the input into tokens during file input, you might want to wrap the input stream (be it a FileReader, whatever) around a StreamTokenizer, like this:
But if you just want to parse a string into tokens, then the following will suffice:
However, StringTokenizer is now considered a legacy class and is only retained for compatibility purposes. You could try using String's split method:
|