Print unicode character from variable (swift)

前端 未结 6 440
耶瑟儿~
耶瑟儿~ 2020-11-30 14:53

I have a problem I couldn\'t find a solution to. I have a string variable holding the unicode \"1f44d\" and I want to convert it to a unicode character

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 15:28

    Here are a couple ways to do it:

    let string = "1f44d"
    

    Solution 1:

    "&#x\(string);".applyingTransform(.toXMLHex, reverse: true)
    

    Solution 2:

    "U+\(string)".applyingTransform(StringTransform("Hex/Unicode"), reverse: true)
    

提交回复
热议问题