Last active
February 12, 2020 10:22
-
-
Save 18o/ad0f434586f59d2c821037ec35908dea to your computer and use it in GitHub Desktop.
golang unicode to utf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't work