我知道如何让 Java 扫描仪不关心大小写,但是如何让它不关心标点符号呢?我想这样做,这样我就不必输入所有这些:
if (mirioutput.equalsIgnoreCase("You're an idiot.") ||
mirioutput.equalsIgnoreCase("Your an idiot.") ||
mirioutput.equalsIgnoreCase("You're an idiot") ||
mirioutput.equalsIgnoreCase("Youre an idiot") ||)
{
//code goes here
}
顺便说一句,如果你想知道为什么文本说“你是个白痴”,我正在尝试制作一个类似 Siri 的程序,它会响应你键入的内容。
最佳答案
您可以删除所有非字母和数字字符
mirioutput = mirioutput.replaceAll("[^A-Za-Z9-0]","");
关于java - 如何让Java中的扫描仪不关心标点符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39922107/