我正在尝试编写一个可以响应文本的基本 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。我想禁用该编辑文本中的大写字母过滤器。我该怎么做?
谢谢!
最佳答案
您可以将 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");
关于android - 如何在 android 中制作 "contains"以忽略字母的大写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17043523/