How do you encode unicode code points in Go? In the example below I'm storing the hex representation of the unicode for ace of spades as \u1F0A1
but when I print it comes out as Ἂ1
. Why is that? If I copy and paste the ace of spades glyph it prints fine.
package main
import "fmt"
func main() {
fmt.Println("🂡 \u1F0A1")
}
Output
🂡 Ἂ1
Example above in the Go playground https://play.golang.org/p/ukK57CnVuE
Lowercase \u
is for Unicode code points from \u0000
to \uFFFF
. Use \U
if you want to have code points above 0xFFFF:
package main
import "fmt"
func main() {
fmt.Println("🂡 = \U0001F0A1")
}
See also: playground and the string literals section of the specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With