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

后端 未结 15 2136
终归单人心
终归单人心 2021-02-02 07:10

I want to change persian numbers which are saved in variable like this :

string Value=\"۱۰۳۶۷۵۱\"; 

to

string Value=\"1036751\"         


        
15条回答
  •  再見小時候
    2021-02-02 07:40

    Useful and concise:

    public static class Utility
        {
            // '۰' = 1632
            // '0' = 48
            // ------------
            //  1632  => '۰'
            //- 1584
            //--------
            //   48   => '0'
            public static string GetEnglish(this string input)
            {
                char[] persianDigitsAscii = input.ToCharArray(); //{ 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641 };
                string output = "";
                for (int k = 0; k < persianDigitsAscii.Length; k++)
                {
                    persianDigitsAscii[k] = (char) (persianDigitsAscii[k] - 1584);
                    output += persianDigitsAscii[k];
                }
    
                 return output;
            }
        }
    

提交回复
热议问题