0

i want to check the text if it was arabic show the letter in the other text if it is for example was english or korean show the error message saying enter an arabic text but it shows the error message both ways if i write arabic or english or any other language and iam 100% sure about the letters i entered on the text matches the ascii on the if statment so what iam i doing wrong ??!!!

public class MainActivity extends Activity {

EditText te1;
EditText te2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    te1 = (EditText) findViewById(R.id.t1);
    te2 = (EditText) findViewById(R.id.t2);

final AlertDialog ad;
    ad = new AlertDialog.Builder(this).create();
    ad.setTitle("رسالة خطأ");
    ad.setMessage("رجاء  ادخل نص عربي  ");
    ad.setButton("موافق^_*", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            // TODO Auto-generated method stub
             dialog.dismiss(); 
        }

    });



    final Button v = (Button) findViewById(R.id.b1);
    v.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // imva.setImageResource(R.id.b1);






            for ( int j = 0 ; j < te1.length() ; j++)
            {
            String l =  te1.toString();
      char coverLetter =l.charAt(j);    

 if ((coverLetter >= 1569) && (coverLetter <= 1594) || (coverLetter >= 1600) && (coverLetter<= 1610))

      {     
          te2.setText("غ ");

      }
      else 
        {

            ad.show();
        }

        }// for 
        } 
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

nona
  • 9
  • 2

1 Answers1

0

To check for Arabic text, you can use regular expressions:

using System.Text.RegularExpressions;

bool isArabic = Regex.IsMatch(text,@"[\p{IsArabic}]+");

To account for spaces in between text:

bool isArabic = Regex.IsMatch(text,@"[\p{IsArabic}\s]+");
Jerry
  • 4,258
  • 3
  • 31
  • 58
  • Can't you use the same Regexes on Android? – Jerry Apr 30 '13 at 15:04
  • @ Jerry i tryed but it keeps giving me error on this line using System.Text.RegularExpressions; – nona Apr 30 '13 at 16:22
  • @ Jerry i found a way and it worked thank you for answering me – nona Apr 30 '13 at 17:27
  • I'm glad it worked. Anyway here is a link for regexes for Android: http://stackoverflow.com/questions/1129996/how-do-i-create-a-regular-expression-for-this-in-android – Jerry Apr 30 '13 at 17:30