I want to change persian numbers which are saved in variable like this :
string Value="۱۰۳۶۷۵۱";
to
string Value="1036751";
How can I use easy way like culture info to do this please?
my sample code is:
List<string> NERKHCOlist = new List<string>();
NERKHCOlist = ScrappingFunction(NERKHCO, NERKHCOlist);
int NERKHCO_Price = int.Parse(NERKHCOlist[0]);//NERKHCOlist[0]=۱۰۳۶۷۵۱
<= So it can not Parsed it to int
And This is in my function which retun a list with persian digits inside list items
protected List<string> ScrappingFunction(string SiteAddress, List<string> NodesList)
{
string Price = "null";
List<string> Targets = new List<string>();
foreach (var path in NodesList)
{
HtmlNode node = document.DocumentNode.SelectSingleNode(path.ToString());//recognizing Target Node
Price = node.InnerHtml;//put text of target node in variable(PERSIAN DIGITS)
Targets.Add(Price);
}
return Targets;
}
Here my code convert Persian digits in variable to English , By extension method(Can use with dot after your expression)
and when you want to use this code have to write : txt1.Value.ToEnglishNumber();
You need to parse them first, using e.g. Int32.Parse() with the correct cultural specifier. Once you have it as a plain integer, it's simply a matter of calling ToString() on it, again with the correct cultural specifier.
An alternative solution is to walk the string character by character and just replace any character that is a Persian digit with the corresponding (west) arabic numeral. Other characters can then be preserved as-is, if required.
If the string really contains a number, you should go with the integer parsing method. If it is not just a number, but really a phone number, serial number etc, you might need to use the replacing algorithm instead.
USE Culture To convert the number from any language to any language
Functions:
How to use the functions:
Result:
r1:
"۰۰۱۱۲۲۳۳۴۴۵۵۶۶۷۷۸۸۹۹"
r2:
"00112233445566778899"
r3:
"۰۱۲۳۴۵۶۷۸۹"
You can manually convert them like so
I don't know the persian numbers so you will have to add them into the char array.
I wrote this extension method to convert Arabic and Persian digits in an string to its Latin representation