Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect Arabic or Persian character in string by c#?

Tags:

c#

I want to detect Arabic or Persian character in a string.

For example:

search in string = "مشخصات، قیمت و خرید لپ تاپ 15 اینچی ایسر مدل Aspire ES1-533-C4UH"

and return true

and search in string="Aspire ES1-533-C4UH"

and return false

string pattern = @"^[\p{IsArabic}\s\p{N}]+$";
string input = @"مشخصات، قیمت و خرید لپ تاپ 15 اینچی ایسر مدل Aspire ES1-533-C4UH";
RegexOptions options = RegexOptions.RightToLeft;"

foreach (Match m in Regex.Matches(input, pattern, options))
{
    if(m.Value !="")
    {
        bool x=true;
    }
    else
        x=false;
}

but this doesn not work.

like image 676
HIV88 Avatar asked Aug 30 '17 13:08

HIV88


Video Answer


1 Answers

Try using this (I'm using it and it works).

This Regex accepts all arabic letters by UTF ranges.

Regex regex = new Regex("[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]");
return regex.IsMatch(text);
like image 100
Koby Douek Avatar answered Sep 23 '22 14:09

Koby Douek