I want to change persian numbers which are saved in variable like this :
string Value=\"۱۰۳۶۷۵۱\";
to
string Value=\"1036751\"
Here my code convert Persian digits in variable to English , By extension method(Can use with dot after your expression)
private static readonly string[] pn = { "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" };
private static readonly string[] en = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
public static string ToEnglishNumber(this string strNum)
{
string chash = strNum;
for (int i = 0; i < 10; i++)
chash = chash.Replace(pn[i], en[i]);
return chash;
}
public static string ToEnglishNumber(this int intNum)
{
string chash = intNum.ToString();
for (int i = 0; i < 10; i++)
chash = chash.Replace(pn[i], en[i]);
return chash;
}
and when you want to use this code have to write : txt1.Value.ToEnglishNumber();