String a ="the STRING TOKENIZER CLASS ALLOWS an APPLICATION to BREAK a STRING into TOKENS. ";
StringTokenizer st = new StringTokenizer(a);
while (st.hasMoreTokens()){
System.out.println(st.nextToken());
给定上面的代码,输出如下,
the
STRING TOKENIZER CLASS
ALLOWS
an
APPLICATION
to
BREAK
a
STRING
into
TOKENS.
我唯一的问题是为什么“STRING TOKENIZER CLASS”被合并为一个令牌?????????
当我尝试运行此代码时,
System.out.println("STRING TOKENIZER CLASS".contains(" "));
它打印出有趣的结果,
错误的
听起来不合逻辑吧?我不知道出了什么问题。
我找到了原因,该空间未被Java以某种方式识别为有效空间。但是,我不知道从前端处理到我发布的代码是如何变成这样的。
伙计们,我需要强调一下,下面的代码在上面的代码之前首先运行..
if (!suspectedContentCollector.isEmpty()){ 迭代器 i =susspectedContentCollector.iterator(); 字符串临时=“”;while (i.hasNext()){ temp+=i.next().toLowerCase()+ " "; } StringTokenizer st = new StringTokenizer(temp);
while (st.hasMoreTokens()){
temp=st.nextToken();
temp=StopWordsRemover.remove(temp);
analyzedSentence = analyzedSentence.replace(temp,temp.toUpperCase());
}
}
因此,一旦将其更改为大写,某处似乎出现了问题,我意识到只有某些空格未被识别。这可能是从文档中检索文本的原因吗?
以下代码,
String a ="STRING TOKENIZER CLASS 允许应用程序将字符串分解为 TOKENS。"; for (int i : a.toCharArray()) { System.out.print(i + " "); }
产生以下输出,
116 104 101 32 83 84 82 73 78 71 160 84 79 79 75 69 78 78 73 90 69 82 160 67 76 67 76 65 83 83 83 83 32 65 76 76 76 79 87 87 83 32 97 83 32 97 110 32 65 80 80 80 80 76 76 76 73 67 67 67 67 65 84 79 79 79 79 79 78 32 78 32 78 32 78 32 78 32 78 32 78 32 78 32 78 32 78 32 78 32 78 32 116 111 32 66 82 69 65 75 32 97 32 83 84 82 73 78 71 32 105 110 116 111 32 84 79 75 69 78 83 46 160 32