static String ConvertDigitsToLatin(String s) {
var sb = new StringBuffer();
for (int i = 0; i < s.length; i++) {
switch (s[i]) {
//Persian digits
case '\u06f0':
sb.write('0');
break;
case '\u06f1':
sb.write('1');
break;
case '\u06f2':
sb.write('2');
break;
case '\u06f3':
sb.write('3');
break;
case '\u06f4':
sb.write('4');
break;
case '\u06f5':
sb.write('5');
break;
case '\u06f6':
sb.write('6');
break;
case '\u06f7':
sb.write('7');
break;
case '\u06f8':
sb.write('8');
break;
case '\u06f9':
sb.write('9');
break;
//Arabic digits
case '\u0660':
sb.write('0');
break;
case '\u0661':
sb.write('1');
break;
case '\u0662':
sb.write('2');
break;
case '\u0663':
sb.write('3');
break;
case '\u0664':
sb.write('4');
break;
case '\u0665':
sb.write('5');
break;
case '\u0666':
sb.write('6');
break;
case '\u0667':
sb.write('7');
break;
case '\u0668':
sb.write('8');
break;
case '\u0669':
sb.write('9');
break;
default:
sb.write(s[i]);
break;
}
}
return sb.toString();
}
6条答案
按热度按时间dphi5xsq1#
示例:
iklwldmw2#
b4qexyjb3#
不确定你会在什么上下文中使用这些数字,但我宁愿定义一个常量Map:
const numberMap = {0: '۰', 1: '۱', 2:'۲', 3:'۳', 4:'٤', 5:'۵', 6:'٦', 7:'۷', 8:'۸',9: '۹'};
然后你可以调用numberMap[number]
来重用它。628mspwn4#
根据此答案:https://stackoverflow.com/a/63934087/14409491
jtoj6r0c5#
下面是我的解决方案:
pes8fvy96#