Swift中的印地语数字设置整数值

时间:2019-02-15 11:29:31

标签: ios swift

是否有任何无需使用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

1 个答案:

答案 0 :(得分:4)

使用NumberFormatter

    let numberFormat= NumberFormatter()
    numberFormat.locale = Locale(identifier: "EN")
    if let getOP = numberFormat.number(from: "४")
    {
        print("output is: ", getOP)
    }

enter image description here