Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i used this function to Converting Numbers from Western Arabic Digits "1,2,3..." to Eastern Arabic Digits "١, ٢, ٣...."
how can reverse this code to
Converting Numbers from Eastern Arabic Digits "١, ٢, ٣...." to Western Arabic Digits "1,2,3..."

Public Function Translatear(ByVal sIn As String) As String

       Dim enc As New System.Text.UTF8Encoding
       Dim utf8Decoder As System.Text.Decoder
       utf8Decoder = enc.GetDecoder
       Dim sTranslated = New System.Text.StringBuilder
       Dim cTransChar(1) As Char
       Dim bytes() As Byte = {217, 160}
       ' Start Converting characters into Arabic mode.
       Dim aChars() As Char = sIn.ToCharArray
       For Each c As Char In aChars
           If Char.IsDigit(c) Then
               bytes(1) = 160 + CInt(Char.GetNumericValue(c))
               utf8Decoder.GetChars(bytes, 0, 2, cTransChar, 0)
               sTranslated.Append(cTransChar(0))
           Else
               sTranslated.Append(c)
           End If
       Next
       Return sTranslated.ToString
   End Function


What I have tried:

Converting Numbers from Eastern Arabic Digits "١, ٢, ٣...." to Western Arabic Digits "1,2,3..."
in the same modality
Posted
Updated 10-Apr-22 22:17pm

1 solution

You need a translate table which matches the Eastern numbers to Western, and vice versa. One should containing all the Eastern Arabic digits in order from zero, and the other containing the Western ones. You can then do a lookup in either table to find its corresponding number in the alternate coding.
C# sample as my VB skills are not very good.
C#
string eastern = "٠١٢٣٤٥٦٧٨٩";
string western = "0123456789";
string result = "";
foreach (char c in number)
{
    int index = eastern.IndexOf(c);
    c = western[index];
    result += c;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900