You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
456 B
23 lines
456 B
|
4 years ago
|
package common
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
//Unicode转中文
|
||
|
|
func ZhToUnicode(raw []byte) (string, error) {
|
||
|
|
str, err := strconv.Unquote(strings.Replace(strconv.Quote(string(raw)), `\\u`, `\u`, -1))
|
||
|
|
if err != nil {
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
return string([]byte(str)), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
//中文转Unicode
|
||
|
|
func UnicodeToZh(sText string) string {
|
||
|
|
textQuoted := strconv.QuoteToASCII(sText)
|
||
|
|
textUnquoted := textQuoted[1 : len(textQuoted)-1]
|
||
|
|
return textUnquoted
|
||
|
|
}
|