Skip to content

Instantly share code, notes, and snippets.

@18o
Last active February 12, 2020 10:22
Show Gist options
  • Save 18o/ad0f434586f59d2c821037ec35908dea to your computer and use it in GitHub Desktop.
Save 18o/ad0f434586f59d2c821037ec35908dea to your computer and use it in GitHub Desktop.
golang unicode to utf8
func unicode2utf8(source string) string {
var res = []string{""}
sUnicode := strings.Split(source, "\\u")
var context = ""
for _, v := range sUnicode {
var additional = ""
if len(v) < 1 {
continue
}
if len(v) > 4 {
rs := []rune(v)
v = string(rs[:4])
additional = string(rs[4:])
}
temp, err := strconv.ParseInt(v, 16, 32)
if err != nil {
context += v
}
context += fmt.Sprintf("%c", temp)
context += additional
}
res = append(res, context)
return strings.Join(res, "")
}
@DarkMagician55
Copy link

it doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment