Print unicode character from variable (swift)

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

    As of Swift 2.0, every Int type has an initializer able to take String as an input. You can then easily generate an UnicodeScalar corresponding and print it afterwards. Without having to change your representation of chars as string ;).

    UPDATED: Swift 3.0 changed UnicodeScalar initializer

    print("\u{1f44d}") // 

提交回复
热议问题