Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine a string is english or arabic?

Tags:

java

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

like image 1000
Victor S Avatar asked Feb 27 '13 08:02

Victor S


People also ask

How do I know if a string is Arabic?

https://www.npmjs.com/package/is-arabic It checks both Arabic and Farsi letters and Unicode as well. It also checks for Arabic symbols, Harakat, and numbers. You can also make it check for a certain number of characters.By default it checks if the whole string is Arabic.

How do you identify a letter in a string?

You can use string. indexOf('a') . If the char a is present in string : it returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.


1 Answers

Here is a simple logic that I just tried:

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

It declares the text as arabic if and only if an arabic unicode code point is found in the text. You can enhance this logic to be more suitable for your needs.

The range 0600 - 06E0 is the code point range of Arabic characters and symbols (See Unicode tables)

like image 165
Eyal Schneider Avatar answered Sep 22 '22 08:09

Eyal Schneider