我有字符串比较问题,if语句总是失败。 但是我得到了正确的结果(变量)" oui"或"非"
String result = sb.toString();
String OK_ = "oui";
Log.i("Responce", "" + result);
if (result.equals(OK_)) {
Toast.makeText(getApplicationContext(),
"Connected",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error"+result,
Toast.LENGTH_LONG).show();
}
答案 0 :(得分:2)
在结果字符串中可能有大写字母,所以
if (result.trim().equalsIgnoreCase(OK_)) {
Toast.makeText(getApplicationContext(),
"Connected",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error"+result,
Toast.LENGTH_LONG).show();
}