Alex Rivera | Logout

How to convert Arabic number to int?

Asked 2011-05-04T06:30:42.090
23

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#. Any solution or help please? thanks in advance


From comments:

I have arabic numbers like ١،٢،٣،٤... and must convert to 1,2,3, or ٢٣٤ convert to 234

c#
Edit
Report

2 Answers

10

Unfortunately it is not yet possible to parse the complete string representation by passing in an appropriate IFormatProvider(maybe in the upcoming versions). However, the char type has a GetNumericValue method which converts any numeric Unicode character to a double. For example:

double two = char.GetNumericValue('٢');
Console.WriteLine(two); // prints 2

You could use it to convert one digit at a time.

answered 2012-03-20T12:28:46.073
9

Arabic digits like ١،٢،٣،٤ in unicode are encoded as characters in the range 1632 to 1641. Subtract the unicode for arabic zero (1632) from the unicode value of each arabic digit character to get their digital values. Multiply each digital value with its place value and sum the results to get the integer.

Alternatively use Regex.Replace to convert the string with Arabic digits into a string with decimal digits, then use Int.Parse to convert the result into an integer.

answered 2011-05-04T06:45:22.677

Your Answer