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

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

    use this static class to change normalize number easily:

    public static class Numbers
    {
        public static string ChangeToEnglishNumber(this string text)
        {
            var englishNumbers = string.Empty;
            for (var i = 0; i < text.Length; i++)
            {
                if(char.IsNumber(text[i])) englishNumbers += char.GetNumericValue(text, i);
                else englishNumbers += text[i];
            }
    
            return englishNumbers;
        }
    }
    

    Sample:

    string test = "۱۰۳۶۷۵۱".ChangeToEnglishNumber(); // => 1036751
    

提交回复
热议问题