golang 有很多需要将中文转成utf8的
网上搜到一个直接转的,记录下,备用
package main import "golang.org/x/text/encoding/simplifiedchinese" type Charset string const ( UTF8 = Charset("UTF-8") GB18030 = Charset("GB18030") ) func ConvertByte2String(byte []byte, charset Charset) string { var str string switch charset { case GB18030: var decodeBytes,_=simplifiedchinese.GB18030.NewDecoder().Bytes(byte) str= string(decodeBytes) case UTF8: fallthrough default: str = string(byte) } return str }
原文地址:https://www.cnblogs.com/zhishuai/p/8593138.html
时间: 2024-11-05 18:35:38