[英]How to convert special characters in dictionary to unicode in swift
//temporary dictionary
let tempDict = ["ttTasks":"€ is euro symbol"]
//轉換應該用\\ u20ac替換€符號
所以最后的字典會是
finalDict = ["ttTasks":"\u20ac is euro symbol"]
注意:請不要建議我使用replaceOccurencesOfString
因為我需要為每個特殊字符執行此操作。
這樣的事情可能是:
for key in tempDict.keys {
let data = tempDict[key]?.data(using: String.Encoding.nonLossyASCII)
tempDict[key] = String(data: data!, encoding: String.Encoding.utf8)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.