【问题标题】:How to convert special characters in dictionary to unicode in swift如何在swift中将字典中的特殊字符转换为unicode
【发布时间】:2016-11-18 09:46:05
【问题描述】:
//temporary dictionary
let tempDict =  ["ttTasks":"€ is euro symbol"]

//转换应该用\u20ac替换€符号

所以最终的字典应该是

finalDict = ["ttTasks":"\u20ac is euro symbol"] 

注意:请不要建议我replaceOccurencesOfString,因为我需要为每个特殊字符执行此操作。

【问题讨论】:

    标签: ios swift string unicode


    【解决方案1】:

    可能是这样的:

    for key in tempDict.keys {
        let data = tempDict[key]?.data(using: String.Encoding.nonLossyASCII)
        tempDict[key] = String(data: data!, encoding: String.Encoding.utf8)
    }
    

    【讨论】:

    • 另一个快速的问题,我在输出中得到双斜杠无论如何我可以编辑上面的代码以获得单斜杠。 [“ttTasks”:“\\u20ac”]
    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 2022-07-21
    • 2016-07-08
    • 1970-01-01
    • 2017-09-25
    相关资源
    最近更新 更多