Reputation: 71
hi friend
i have two strings in persian language in android for example
String a = "آرمین"; String b = "آرمین2";
how can i compare this strings in android? are there any method ?
Upvotes: 2
Views: 1039
Reputation: 913
The following uses length() and charAt(index i) methods to implement String.equals() method.
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");
Upvotes: 2
Reputation: 21
Example :
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();
Good Luck موفق باشی
Upvotes: -1