stringtokenizer that traps ASCII linebreaks  
Author Message
wnstnsmith





PostPosted: 2004-2-12 3:43:00 Top

java-programmer, stringtokenizer that traps ASCII linebreaks Dear all,

How do i define a stringtokenizer that traps chr13, chr10 combinations?

tia
WS
 
Adam Jenkins





PostPosted: 2004-2-12 4:00:00 Top

java-programmer >> stringtokenizer that traps ASCII linebreaks email***@***.com wrote:
> Dear all,
>
> How do i define a stringtokenizer that traps chr13, chr10 combinations?
>
> tia
> WS

You can't exactly do this with StringTokenizer, since it doesn't support
splitting on specific multi-char patterns. You could say

StringTokenizer stok = new StringTokenizer(string, "\r\n");

which would split "string" at each \013\010, but it would also split on
just a \013 or \010 or \013\013, etc. If you really need to split at
each \r\n, then you can use String.split, as in

String[] tokens = string.split("\r\n");

Adam

 
wnstnsmith





PostPosted: 2004-2-12 6:04:00 Top

java-programmer >> stringtokenizer that traps ASCII linebreaks Thanks very much indeed, that does it. Guess my mistake was to have the
tokenizer look for '\r' + '\n' + "blablabla", instead of "\r\n". You can
imagine that had me wondering...

WS