I have a requirement, I have a textfield which I'm fetching the data from database. It may be in Arabic or in English. I want to differentiate it dynamically and change alignment accordingly. ie, if the text is in Arabic it should be from right to left else left to right.
You can said that the text is in arabic, if count of arabic characters is more than count of english characters.
You can determine it using character classes in regular expression
public bool IsArabic(this string input)
{
var isArabic = Regex.Matches(input, "\\p{IsArabic}");
var isLatin = Regex.Matches(input, "\\p{IsBasicLatin}");
if (isArabic == null)
return false;
if (isLatin == null)
return true; //suggest that there is no another character types
if (isArabic.Count > isLatin.Count)
return true;
return false;
}