1
votes

I'm building a map of emoji unified unicode characters to their common names. I have strings representing each emoji, in UTF16 format. For example, the string "00A9" represents the copyright symbol. I need to convert that into a utf8 rune, so I can compare it to input I receive from the user, but I haven't found the right incantation of the hex/utf16/utf8 packages to do so.

3

3 Answers

1
votes

Parse the hex string as an integer. Use a string conversion to convert the integer to UTF-8.

n, err := strconv.ParseInt("00A9", 16, 32)
if err != nil {
    log.Fatal(err)
}
s := string(rune(n))

playground example

0
votes

you can try lib: codepage detect

s := "..."
s = cpd.DecodeUTF16be(s)
s = cpd.DecodeUTF16le(s)