Convert Arabic to English

I am looking for a way to convert the Arabic numeric string "0123456789" into English, the numeric string "0123456789"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dim Anum as string ="٠١٢٣٤٥٦٧٨٩" dim Enum as string =get_egnlishNum(Anum) End Sub private function get_egnlishNum(byval _Anum as string) as string '' converting code end function 
+4
source share
4 answers

You are looking for a GetNumericValue method of type char that converts any Unicode numeric character to double. For instance:

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

In your example:

 static string ArabicToWestern(string input) { StringBuilder western = new StringBuilder(); foreach(char num in input) { western.Append(char.GetNumericValue(num)); } return western.ToString(); } 

Change your needs.

VB.NET:

 Private Shared Function ArabicToWestern(ByVal input As String) As String Dim western As StringBuilder = New StringBuilder For Each num As Char In input western.Append(Char.GetNumericValue(num)) Next Return western.ToString End Function 
+3
source

This is one of the solutions.

 Function Convert(ByVal input As String) As String Dim source = "٠١٢٣٤٥٦٧٨٩" Dim target = "0123456789" Dim sb As New StringBuilder() For Each el in Input sb.Append(target(source.IndexOf(el))) Next Return sb.ToString End Function 

EDIT

I tried to find more "native" ways. I found the NativeDigits property of the NumberFormatInfo class

This was my test code, but it failed. But that could be a good starting point.

  Dim source = "١٢٣٤٥٦٧٨٩" Dim result As Integer Dim numInfo As new NumberFormatInfo() numInfo.NativeDigits = New String() { "٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩" } Int32.TryParse(source, NumberStyles.Any, numInfo, result) 
+2
source

You can simply replace the Arabic characters with the western versions:

 Dim arabicDigits = "٠١٢٣٤٥٦٧٨٩".ToCharArray Dim s = "‏٠٦٦٢٧٣٩٦عدد النقاط هي ٩٩٣٩٣٥" For i = 0 To arabicDigits.Length - 1 s = s.Replace(arabicDigits(i), i.ToString) Next 

s now contains "06627396 عدد النقاط هي 993935"

+1
source
 Dim arabicDigits = "٠١٢٣٤٥٦٧٨٩".ToCharArray dim i as integer=0 For i = 0 To anum.Length - 1 select case arabicDigits(i) case "٠" Replace(arabicDigits(i),"0") case "١" Replace(arabicDigits(i),"1") case "٢" Replace(arabicDigits(i),"2") case "٣" Replace(arabicDigits(i),"3") case "٤" Replace(arabicDigits(i),"4") case "٥" Replace(arabicDigits(i),"5") case "٦" Replace(arabicDigits(i),"6") case "٧" Replace(arabicDigits(i),"7") case "٨" Replace(arabicDigits(i),"8") case "٩" Replace(arabicDigits(i),"9") i=i+1 endselect End Sub 
0
source

Source: https://habr.com/ru/post/1402415/


All Articles