This is a creation in Article, where the information may have evolved or changed.
Converting Chinese to Unicode, using quotetoascii directly in the StrConv package in Golang, converting Unicode codes to Chinese is a bit trickier, first split the Unicode encoding by \u, and then use StrConv. Parseint, converts the 16 binary number to Int64, in the use of FMT. sprintf converts a number to a character and finally joins it together, so it becomes a Chinese string. The reference code is as follows:
1 Package Main2 3 Import (4 "FMT"5 "StrConv"6 "Strings"7 )8 9 Func Main () {TenStext: ="English" Onetextquoted: =StrConv. Quotetoascii (stext) Atextunquoted: = textquoted[1: Len (textquoted)-1] - FMT. Println (textunquoted) - theSunicodev: = Strings. Split (textunquoted,"\\u") - varContextstring - for_, V: =Range Sunicodev { - ifLen (v) <1 { + Continue - } +Temp, err: = StrConv. parseint (V, -, +) A ifErr! =Nil { at Panic (Err) - } -Context + = FMT. Sprintf ("%c", temp) - } - FMT. Println (context) -}
Operation Result:
1 \u4e2d\u6587 2 English