How to determine a string is english or arabic?

后端 未结 8 1170
我寻月下人不归
我寻月下人不归 2021-01-31 17:47

Is there a way to determine a string is English or Arabic?

8条回答
  •  孤街浪徒
    2021-01-31 18:10

    This answer is somewhat correct. But when we combine Farsi and English letters it returns TRUE!, which is not true. Here I modified the same method so that it works well

     public static boolean isProbablyArabic(String s) {
        for (int i = 0; i < s.length();) {
            int c = s.codePointAt(i);
            if (!(c >= 0x0600 && c <= 0x06E0))
                return false;
            i += Character.charCount(c);
        }
        return true;
    }
    

提交回复
热议问题