【发布时间】:2014-10-23 14:13:39
【问题描述】:
我尝试在数组上创建一个搜索词,但我不知道如何检测该词是否在句子中。 我使用此链接上的代码。 To check if string contains particular word
这是我现在使用的代码。但它不起作用。
for(int x=0;x<=count;x++){
String sentence = name[x] ;
String search = myEditText.getText().toString() ;
if (sentence.toLowerCase().indexOf(search.toLowerCase()) != -1 ) {
name[x] = name2;
schoolid[x] = id2;
}
}
【问题讨论】:
-
"你好,这里是你通常的搜索方式".contains("你好")
-
@MLProgrammer-CiM
contains(s)indexOf(s.toString()) > -1;。 OP 代码应该可以正常工作吗? -
只是提到..这是一个Java问题而不是“android”