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

后端 未结 15 2119
终归单人心
终归单人心 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:31

    public static string ChangeNumberToEnglishNumber(string value)
        {
            string result=string.Empty;
            foreach (char ch in value)
            {
    
                try
                {
                    double convertedChar = char.GetNumericValue(ch);
                    if (convertedChar >= 0 && convertedChar <= 9)
                    {
                        result += convertedChar.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        result += ch;
                    }
    
    
                }
                catch (Exception e)
                {
                    result += ch;
                }
    
            }
    
            return result;
        }
    

提交回复
热议问题