4

我正在寻找一种将阿拉伯数字字符串“٠١٢٣٤٥٦٧٨٩”转换为英文数字字符串“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

4 回答 4

3

您正在寻找将任何数字 Unicode 字符转换为双精度类型的GetNumericValue方法。char例如:

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

对于您的示例:

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

根据您的需要进行修改。

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
于 2012-03-20T11:46:08.310 回答
2

这是解决方案之一。

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

编辑

我试图找出更多的“原生”方式。我发现的是NumberFormatInfo类的NativeDigits属性

这是我的测试代码,但没有成功。但这可能是一个很好的起点。

        Dim source = "١٢٣٤٥٦٧٨٩"
        Dim result As Integer
        Dim numInfo As new NumberFormatInfo()
        numInfo.NativeDigits = New String() { "٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩" }
        Int32.TryParse(source, NumberStyles.Any, numInfo, result)
于 2012-03-20T11:26:53.470 回答
1

您可以简单地将阿拉伯字符替换为西方版本:

Dim arabicDigits = "٠١٢٣٤٥٦٧٨٩".ToCharArray
Dim s = "‏٠٦٦٢٧٣٩٦عدد النقاط هي ٩٩٣٩٣٥"

For i = 0 To arabicDigits.Length - 1
    s = s.Replace(arabicDigits(i), i.ToString)
Next

s 现在包含“‏06627396عدد النقاط هي 993935”

于 2012-03-20T20:50:18.410 回答
0
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
于 2017-04-29T12:18:14.250 回答