我正在开发一个应用程序,我在其中比较字符串,所有字符串都返回true,当字符串包含comma
然后它返回false。 e.g
String a= edittext.getText().toString().toTrim(); // e.g "string,"
String b= textView.getText().toString().toTrim(); // e.g "string,";
if(a.equals(b)){
Log.i("LOG","Matched!");
}else{
Log.i("LOG","Not Matched!");
}
我不知道equals
函数在这种类型的字符串上返回false。
帮助如何匹配这些类型的字符串。
答案 0 :(得分:2)
因为你的拼写错误而返回false!你错过了字符串b声明中的 r 。
校正:
String a="string,";
String b= "string,";
if(a.equals(b)){
Log.i("LOG","Matched!");
}else{
Log.i("LOG","Not Matched!");
}
答案 1 :(得分:0)
我没有看到你的问题? 您(更新)问题中的代码可以正常使用。
它返回(如预期的那样)“匹配!”