朋友
我在android中有两个波斯语言的字符串,例如
String a =“آرمین”; 字符串b =“آرمین2”;
如何在android中比较这些字符串? 有什么方法吗?
答案 0 :(得分:2)
以下使用length()和charAt(index i)方法来实现String.equals()方法。
String string1 = "test";
String string2 = "2test";
int test=0;
if(string1.length() == string2.length()){
for (int i=0;i<string1.length();i++){
if(string1.charAt(i)==string2.charAt(i))
test++;
}
}
if(test == string1.length()){
System.out.println("Strings are equal");
}else
System.out.println("Strings are not equal");
答案 1 :(得分:-1)
示例:
String a = "آرمین"; String b = "آرمین 2";
if(a.equals(b))
Toast.makeText(getApplicationContext(),"Are Equal", Toast.LENGTH_LONG).show();
else
Toast.makeText(getApplicationContext(),"not Equal", Toast.LENGTH_LONG).show();
祝你好运
موفقباشی