Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Arabic number to int?

Tags:

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

like image 333
Shaahin Avatar asked May 04 '11 06:05

Shaahin


People also ask

How can I convert Arabic numbers to English in Excel?

Click File > Options > Language. In the Set the Office Language Preferences dialog box, under Choose Display and Help Languages, select the language that you want to use, and then click Set as Default.

How do you change Persian numbers to English?

Go to File > Options > Advanced. Scroll down to the Show document content section - you will find the Numeral option. Set it to Context.


2 Answers

use this Method

private string toEnglishNumber(string input) {     string EnglishNumbers = "";      for (int i = 0; i < input.Length; i++)     {         if (Char.IsDigit(input[i]))         {             EnglishNumbers += char.GetNumericValue(input, i);         }         else         {             EnglishNumbers += input[i].ToString();         }                }     return EnglishNumbers; } 
like image 188
Mohammad Asghari Avatar answered Sep 30 '22 05:09

Mohammad Asghari


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.

like image 30
Terje Norderhaug Avatar answered Sep 30 '22 05:09

Terje Norderhaug