Last active
June 22, 2024 10:56
-
-
Save spicydog/54703add01e82e3c071482c2ce4e7c22 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import "encoding/json" | |
// Unescape UTF-8 string | |
// e.g. convert "\u0e27\u0e23\u0e0d\u0e32" to "วรญา" | |
func UnescapeString(str string) (unescapedString string) { | |
json.Unmarshal([]byte(`"`+str+`"`), &unescapedString) | |
return | |
} |
rubenhorn excelent solutions very thanks! (y)
There's no need to rely on json.Unmarshal
, instead you can use strconv.Unquote
directly like so (playground):
source := "\u0e27\u0e23\u0e0d\u0e32"
converted, _ := strconv.Unquote(`"` + source + `"`)
fmt.Println(converted)
// prints วรญา
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to escape any the
"
in the JSON: