How do we use an emoji with a rune literal that is beyond I think code point U+265F?
a1 := '\u2665'
- this works
a2 := '\u1F3A8'
- this gives error invalid character literal, more that one character.
Is there a way to represent higher positioned emojis as rune literals?
You may use the
\Usequence followed by 8 hex digits which is the hexadecimal representation of the Unicode codepoint. This is detailed in Spec: Rune literals:For example:
Which outputs (try it on the Go Playground):
Note (response to @torek):
I believe the Go authors chose to require exactly 4 and 8 hex digits because this allows to use the exact same form, the exact same rune literals inside interpreted string literals. E.g. if you want a string that contains 2 runes, one having code point
0x0001F3A8and another rune being4, it could look like this:If the spec would not require exactly 8 hex digits, it would be ambiguous whether the last
'4'is part of the code point or is an individual rune of the string, so you would have to break thestringto a concatenation like"\U1F3A8" + "4".Spec: String literals: