Print unicode character from variable (swift)

前端 未结 6 452
耶瑟儿~
耶瑟儿~ 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:35

    This can be done in two steps:

    1. convert charAsString to Int code
    2. convert code to unicode character

    Second step can be done e.g. like this

    var code = 0x1f44d
    var scalar = UnicodeScalar(code)
    var string = "\(scalar)"
    

    As for first the step, see here how to convert String in hex representation to Int

提交回复
热议问题