I had written a function using dictionary and linq to replace English number to arabic number in any given string. But the function is not replacing exactly. For eg, if english number is 12345, the arabic number is 12534 or 53214 in arabic. What can be the problem?
My function is as follows,
private Dictionary<string, string> NumbersInArabic()
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("0", "٠");
dictionary.Add("1", "١");
dictionary.Add("2", "٢");
dictionary.Add("3", "٣");
dictionary.Add("4", "٤");
dictionary.Add("5", "٥");
dictionary.Add("6", "٦");
dictionary.Add("7", "٧");
dictionary.Add("8", "٨");
dictionary.Add("9", "٩");
return dictionary;
}
private string ReplaceNumberTextToArabic(string text)
{
var newstr = NumbersInArabic().Aggregate(text, (current, value) => current.Replace(value.Key, value.Value));
return newstr.ToString();
}
I have written your method and it is working fine at my end.
I think your problem is some place else.