如何将非英语数字转换为英文数字,如:Swift中的"3486912881"到"3486912881",或者我想接受英文数字并获取其他数字.
在Java Android中,这段代码对我有用:
private static String arabicToDecimal(String number) {
char[] chars = new char[number.length()];
for(int i=0;i<number.length();i++) {
char ch = number.charAt(i);
if (ch >= 0x0660 && ch <= 0x0669)
ch -= 0x0660 - '0';
else if (ch >= 0x06f0 && ch <= 0x06F9)
ch -= 0x06f0 - '0';
chars[i] = ch;
}
return new String(chars);
}
Run Code Online (Sandbox Code Playgroud) 在不使用 NSString 帮助的情况下,是否有任何纯粹的快速方法可以将印地语/其他语言整数转换为 Int 以下是我的观察:
let string = "?"
let intParse1 = Int(string) //goes for nil, why? is there any pure solution in swift
let intParse2 = (string as NSString).integerValue //goes for 4
Run Code Online (Sandbox Code Playgroud)