ssdjgru1
asked on
StreamTokenizer separators...
I would like to know how to set to which separators the StreamTokenizer will "react". It is easy to set separatorst for StringTokenizer but it doesn't work with StreamTokenizer in that way.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops. Sorry that's the one I meant. the whitespaceChars(int, int) method allows you to specify a range of characters that are considered to be whitespace (whitespace characters that you specify are your tokens.)
The following code:
StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader("B.java")));
st.whitespaceChars('|','|' );
creates a StreamTokenizer that considers the characters from '|' to '|' (i.e. just '|') to be the only tokens in the StreamTokenizer. That is how you set a token.
Use resetSyntax to reset the Tokenizer so that everything is considered "ordinary" (i.e. no tokens) and then set your own tokens using the whitespaceChars.
It does say that it takes int's, but by passing it characters, you are passing it the UNICODE value for those characters.
Good luck, drop a note if I'm still confusing :)
Laminamia :)
The following code:
StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader("B.java")));
st.whitespaceChars('|','|'
creates a StreamTokenizer that considers the characters from '|' to '|' (i.e. just '|') to be the only tokens in the StreamTokenizer. That is how you set a token.
Use resetSyntax to reset the Tokenizer so that everything is considered "ordinary" (i.e. no tokens) and then set your own tokens using the whitespaceChars.
It does say that it takes int's, but by passing it characters, you are passing it the UNICODE value for those characters.
Good luck, drop a note if I'm still confusing :)
Laminamia :)
ASKER
There is whitespaceChars(int,int),v