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
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.
Go to File > Options > Advanced. Scroll down to the Show document content section - you will find the Numeral option. Set it to Context.
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; }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With