I have a list of strings , which may contain english
numbers and arabic
numbers.
What I need to do is to convert arabic
numbers in to english
numbers.
for which I am using the below code .
private string toEnglishNumber(string input)
{
string EnglishNumbers = "";
for (int i = 0; i < input.Length; i )
{
if (Char.IsDigit(input[i]))
{
EnglishNumbers = char.GetNumericValue(input, i);
}
else
{
EnglishNumbers = input[i].ToString();
}
}
return EnglishNumbers;
}
Now I need to make sure before passing my string in to this function that string contains the arabic numbers for example :
List of strings :
[
"٠٥٥ ٥٣٠ ٨٦٨٤" , " 966557864894"
]
So instead of passing both string , I just need to pass only 0 index string which contains arabic numbers , how can I do it.
CodePudding user response:
You can use this method:
public static bool HasArabicGlyphs(string text)
{
foreach (char glyph in text)
{
if (glyph >= 0x600 && glyph <= 0x6ff) return true;
if (glyph >= 0x750 && glyph <= 0x77f) return true;
if (glyph >= 0xfb50 && glyph <= 0xfc3f) return true;
if (glyph >= 0xfe70 && glyph <= 0xfefc) return true;
}
return false;
}
List<string> arabicStrings = stringList.FindAll(HasArabicGlyphs);
Credits to Hans here