如何在以字符串s为参数的StringToekenizer对象中分离标记?

所以:

String s = input.readLine();
char tokenSeparator = ' '; //can be any value other than white space.
StringTokenizer str = new StringTokenizer(s);
//separate tokens by the variable char tokenSeparator;
while (str.hasMoreTokens) ...

最佳答案

检查javadoc。您可以看到一个参数化的构造函数为

public StringTokenizer(String str, String delim)


这就是您的要求。



String msg = "http://100.15.111.60:80/";
char tokenSeparatpor = ':';
StringTokenizer st = new StringTokenizer(msg,tokenSeparatpor+"");
while(st.hasMoreTokens()){
    System.out.println(st.nextToken());
}


输出量

http
//100.15.111.60
80/

关于java - StringTokenizer使用字符分隔 token ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13770159/

10-15 18:56