TokTest.java Illustrates parsing a string with a StringTokenizer.
import java.util.StringTokenizer;
/** Prints the tokens resulting from treating the first
* command-line argument as the string to be tokenized
* and the second as the delimiter set.
*
* Taken from Core Web Programming from
* Prentice Hall and Sun Microsystems Press,
* .
* © 2001 Marty Hall and Larry Brown;
* may be freely used or adapted.
*/
public class TokTest {
public static void main(String[] args) {
if (args.length == 2) {
String input = args[0], delimiters = args[1];
StringTokenizer tok =
new StringTokenizer(input, delimiters);
while (tok.hasMoreTokens()) {
System.out.println(tok.nextToken());
}
} else {
System.out.println
("Usage: java TokTest string delimeters");
}
}
}
Similar Posts
Machine Learning, Big Data, Data Science, Analytics, Cloud, Security, AI, Robotics, Database, BI, Development: Software, Web, Mobile