美文网首页
swift Unicode转码

swift Unicode转码

作者: 番茄炒西红柿啊 | 来源:发表于2018-05-30 13:32 被阅读481次
    extension String {
        var unicodeStr:String {
            let tempStr1 = self.replacingOccurrences(of: "\\u", with: "\\U")
            let tempStr2 = tempStr1.replacingOccurrences(of: "\"", with: "\\\"")
            let tempStr3 = "\"".appending(tempStr2).appending("\"")
            let tempData = tempStr3.data(using: String.Encoding.utf8)
            var returnStr:String = ""
            do {
                returnStr = try PropertyListSerialization.propertyList(from: tempData!, options: [.mutableContainers], format: nil) as! String
            } catch {
                print(error)
            }
            return returnStr.replacingOccurrences(of: "\\r\\n", with: "\n")
        }
    }
    

    相关文章

      网友评论

          本文标题:swift Unicode转码

          本文链接:https://www.haomeiwen.com/subject/kybtsftx.html