Shaunak
Shaunak

Reputation: 717

Convert U+ unicode to NSString

I am referring to this table (https://unicodey.com/emoji-data/table.htm) and want to convert a U+1F1E6 U+1F1FA code to display it in NSString. How can I do that? I don't have the \u format unicode otherwise it would work automatically.

Upvotes: 0

Views: 599

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598134

NSString is encoded as UTF-16, so U+1F1E6 U+1F1FA can be expressed in code using \u notation: "\uD83C\uDDE6\uD83C\uDDFA". Or, if you use \U notation instead, you can use the actual codepoints as-is: "\U0001F1E6\U0001F1FA".

In Swift, it would be expressed as "\u{1F1E6}\u{1F1FA}" instead.

In either case, you can alternatively just put the Unicode characters directly in the string literal and not escape them at all: "🇦🇺".

Upvotes: 2

Related Questions