Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arabic digit to English digit android

Tags:

android

I am using this code for translate English digit into Arabic. But now i am trying to change Arabic digits into English digit.

private void decimalToArabic() {
    String str = showOutputEdit.getText().toString();
    char[] arabicChars = {'٠','١','٢','٣','٤','٥','٦','٧','٨','٩'};
    //  char[] arabicChars = {'٩','٨','٧','٦','٥','٤','٣','٢','١','٠'};
        StringBuilder builder = new StringBuilder();
        for(int i =0;i<str.length();i++)
        { 
            if(Character.isDigit(str.charAt(i)))
            {
                builder.append(arabicChars[(int)(str.charAt(i))-48]);
            }
            else
            {
                builder.append(str.charAt(i));
            }
        }
        System.out.println("Number in English : "+str);
        System.out.println("Number In Arabic : "+builder.toString() );
        showOutputEdit.setText(builder.reverse().toString());
}

what should i need to change?

like image 470
Rahul Rawat Avatar asked Nov 23 '25 19:11

Rahul Rawat


1 Answers

i think you can use something like this.(Here i convert integer to arabic)

 public String convertToArabic(int value)
{
    String newValue =   (((((((((((value+"").replaceAll("1", "١")).replaceAll("2", "٢")).replaceAll("3", "٣")).replaceAll("4", "٤")).replaceAll("5", "٥")).replaceAll("6", "٦")).replaceAll("7", "٧")).replaceAll("8", "٨")).replaceAll("9", "٩")).replaceAll("0", "٠"));       
    return newValue;
}
like image 54
Sanu Avatar answered Nov 26 '25 14:11

Sanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!