golang之处理unicode

import (
	"fmt"
	"strconv"
)

func main() {

	// 中文转换unicode
	s1 := strconv.QuoteToASCII("彬彬")
	// 转换后的
	fmt.Printf("%#v\n",s1) // "\"\\u5f6c\\u5f6c\""

	// unicode转换中文
	fmt.Println(strconv.Unquote(s1)) // 彬彬 <nil>

	// unicode转换中文需要的格式 “内容” ,*注意要传双引号,*外部用来推导类型
   	s2 := 	`"\u63a8\u9001\u6210\u529f"`
	fmt.Println(strconv.Unquote(s2)) // 推送成功 <nil>

	// 自行处理nil
	
}

文档请查
https://studygolang.com/pkgdoc
strconv

posted @ 2020-09-01 15:47  Gaojuqian  阅读(582)  评论(0)    收藏  举报