当前位置 : 主页 > 编程语言 > c语言 >

vb.net – 将阿拉伯数字转换为英语

来源:互联网 收集:自由互联 发布时间:2021-06-24
我正在寻找一种方法将阿拉伯数字字符串“0123456789”转换为英语 数字字符串“0123456789” Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dim Anum as st
我正在寻找一种方法将阿拉伯数字字符串“0123456789”转换为英语
数字字符串“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
您正在寻找char类型的GetNumericValue方法,该方法将任何数字Unicode字符转换为double.例如:

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
网友评论