我正在寻找一种方法将阿拉伯数字字符串“0123456789”转换为英语 数字字符串“0123456789” Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dim Anum as st
数字字符串“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