您好如何在IOS Swift中用字符串中的波斯语替换英文数字
"This is a english text with this numbers 09122223231 34322 "
答案 0 :(得分:2)
将英文数字转换为波斯语的小函数: -
func convertEngNumToPersianNum(num: String)->String{
//let number = NSNumber(value: Int(num)!)
let format = NumberFormatter()
format.locale = Locale(identifier: "fa_IR")
let number = format.number(from: num)
let faNumber = format.string(from: number!)
return faNumber!
}
let string = "This is a english text with this numbers 09122223231 34322 "
if let number = Int(string.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()) {
let perNum = convertEngNumToPersianNum(num: String(number))
print(perNum)
}