Tuesday, July 11, 2006

Java Parse string

import java.util.*;

class ParseString
{
public static void main (String args[])
{
String s = "first,second, third fourth, fifth";
StringTokenizer st;

st = new StringTokenizer (s, ", ");

while (st.hasMoreTokens ())
{
System.out.println (">>" + st.nextToken () + "<<");
}
}
}


The output is:

>>first<<
>>second<<
>>third<<
>>fourth<<
>>fifth<<

0 Comments:

Post a Comment

<< Home