How to convert Arabic number to int?

前端 未结 6 2071
一向
一向 2020-12-05 14:26

I work on a project in C# which requires to use arabic numbers, but then it must store as integer in database, I need a solution to convert arabic numbers into int in C#. An

6条回答
  •  心在旅途
    2020-12-05 14:54

    I know this question is a bit old, however I faced similar case in one of my projects and passed by this question and decided to share my solution which did work perfectly for me, and hope it will serve others the same.

    private string ConvertToWesternArbicNumerals(string input)
    {
        var result = new StringBuilder(input.Length);
    
        foreach (char c in input.ToCharArray())
        {
            //Check if the characters is recognized as UNICODE numeric value if yes
            if (char.IsNumber(c))
            {
                // using char.GetNumericValue() convert numeric Unicode to a double-precision 
                // floating point number (returns the numeric value of the passed char)
                // apend to final string holder
                result.Append(char.GetNumericValue(c));
            }
            else
            {
                // apend non numeric chars to recreate the orignal string with the converted numbers
                result.Append(c);
            }
        }
    
        return result.ToString();
    }
    

    now you can simply call the function to return the western Arabic numerals.

提交回复
热议问题