Domanda

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 ?

È stato utile?

Soluzione

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");

Altri suggerimenti

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 موفق باشی

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top