نرخ یاب نرخ یاب - 3 months ago 47
C# Question

How to Convert Persian Digits in variable to English Digits Using Culture?

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;
}

Answer

You can manually convert them like so

    char[][] numbers = new char[][]
    {
        "0123456789".ToCharArray(),"persian numbers 0-9 here".ToCharArray()
    };
    public void Convert(string problem)
    {
        for (int x = 0; x <= 9; x++)
        {
            problem.Replace(numbers[0][x], numbers[1][x]);
        }
    }

I don't know the persian numbers so you will have to add them into the char array.