일부 콘텐츠가 있는데 콘텐츠에 일부 "searchText"가 있는지 찾으려고합니다. "searchText"에서 한 단어를 찾을 때 String.contains (searchText)는 true를 반환하지만 둘 이상의 작업에 대해 false를 반환합니다. 아래는 구현을 보여주는 스 니펫입니다. searchText가 콘텐츠에 있는지 확인해야합니다.둘 이상의 단어에 대해 String.contains (searchText)가 작동하지 않습니다.
boolean found;
String searchText = "particular text";
String input = "This is the text area where I am trying " +
"to look for the particular text, which is in the variable searchText. " +
"This text will have the string (222M) as part of this string. " +
"The find method should give me a true result even if I don't " +
"enter the closing brakect of the word. This is a multiline string";
if(input.contains(searchText)) {
found = true;
}
정규식을 사용해야합니까? 이전에 언급하지 않은 연구와 시도를 지적하겠습니다.
은 이미 다음과 같은 정규식
pattern = Pattern.compile("(?<=\\W)" + searchText + "(?=\\W)");
이 너무 일을하지 않는 시도했다.
참고 : 이것은 Android에서 제공됩니다.
문자열에 "특정 텍스트"가 포함되어 있기 때문에 * 주어진 경우에는 true가 반환됩니다. 즉, 이미 작동하는 예제를 제공했습니다. * 예상 할 수있는 * 예제를 제공하십시오. 그러나 실제로는 그렇지 않습니다. –
그게 효과가 있습니다. 또한 found = input.contains (searchText) – JesusS
코드가 true를 반환합니다! –