How to convert english numbers inside a string to Persian/Arabic numbers in Objective-C?

前端 未结 10 1979
轮回少年
轮回少年 2021-01-18 10:53

I have an english string that may or may not have numbers. But i want those numbers to be printed on screen as Persian numbers.

For example if NSString *foo =

10条回答
  •  北海茫月
    2021-01-18 11:28

    In swift 3:

    func convertEngNumToPersianNum(num: String)->String{
        let number = NSNumber(value: Int(num)!)
        let format = NumberFormatter()
        format.locale = Locale(identifier: "fa_IR")
        let faNumber = format.string(from: number)
    
        return faNumber!
    }
    

    Check before force unwrap to prevent crash.

提交回复
热议问题