【发布时间】:2015-03-21 18:23:08
【问题描述】:
我必须使用空格来标记字符串,使用这个构造函数:
StringTokenizer st = new StringTokenizer(str, " ");
我觉得是一样的
StringTokenizer st = new StringTokenizer(str);
问题是,当我尝试使用空格作为分隔符时,它只需要第一个标记,所以输出是这样的:
3 5 + //this is the string which has to be tokenized
3 | //these are the tokens it actually takes
如果我用逗号(或除空格以外的任何其他分隔符)做同样的事情,那么:
StringTokenizer st = new StringTokenizer(stringa, ",");
它工作正常,它需要我需要的所有令牌:
3,5,+ //this is the string which has to be tokenized
3 | 5 | //these are the tokens it actually takes
8 | //this is the result of the sum
【问题讨论】:
标签: whitespace token delimiter stringtokenizer