我正在尝试写一个基本的AI来回复文本。
但是,在此代码中;
public void registermessage(View view) {
if (edittext.getText().toString().contains("hello")){
test.setText("Hello, sir.");
} else{
test.setText("It would be better off to say hello first, sir.");
}
每当我写Hello时,它都不会注册为hello。我想在该edittext中禁用任何大写过滤器。我怎么做?
谢谢!
最佳答案
您可以将java.util.regex.Pattern与CASE_INSENSITIVE一起使用:
Pattern.compile(Pattern.quote(your_text), Pattern.CASE_INSENSITIVE).matcher("hello").find();
或者您可以使用以下方法:
org.apache.commons.lang3.StringUtils.containsIgnoreCase(your_text, "hello");