草庐IT

unicode - 如何在 Golang 中将 rune 转换为 unicode 样式的字符串,如 `\u554a`?

如果你运行fmt.Println("\u554a"),它会显示'啊'。但是如何从rune'啊'中获取unicode-style-string\u554a呢? 最佳答案 packagemainimport"fmt"import"strconv"funcmain(){quoted:=strconv.QuoteRuneToASCII('啊')//quoted="'\u554a'"unquoted:=quoted[1:len(quoted)-1]//unquoted="\u554a"fmt.Println(unquoted)}这个输出:\u