问题
This question already has an answer here:
- Print unicode character from variable (swift) 6 answers
How do you convert unicode emoji stored as a string (e.g. 1f564
) to an emoji that could be placed on a UILabel?
let myString = "1f564"
I've seen the use of the escape character but I can't insert variables to replace the characters.
let flag = "\u{1f1e9}\u{1f1ea}"
Thanks
回答1:
This works. I don't know if there is anything more direct:
let myStr = "1f564"
let str = String(UnicodeScalar(Int(myStr, radix: 16)!)!)
来源:https://stackoverflow.com/questions/32555145/convert-unicode-e-g-1f564-to-emoji-in-swift