How to determine a string is english or arabic?

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

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

8条回答
  •  别跟我提以往
    2021-01-31 18:20

    A minor change to cover all arabic characters and symbols range

    private boolean isArabic(String text){
            String textWithoutSpace = text.trim().replaceAll(" ",""); //to ignore whitepace
            for (int i = 0; i < textWithoutSpace.length();) {
                int c = textWithoutSpace.codePointAt(i);
              //range of arabic chars/symbols is from 0x0600 to 0x06ff
                //the arabic letter 'لا' is special case having the range from 0xFE70 to 0xFEFF
                if (c >= 0x0600 && c <=0x06FF || (c >= 0xFE70 && c<=0xFEFF)) 
                    i += Character.charCount(c);   
                else                
                    return false;
    
            } 
            return true;
          }
    

提交回复
热议问题