This commit is contained in:
bense
2022-05-14 13:20:18 +08:00
parent 562d11daaf
commit 13073cd8e4
12 changed files with 129 additions and 77 deletions

20
util/string.go Normal file
View File

@@ -0,0 +1,20 @@
package util
import (
"bytes"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"io/ioutil"
"strings"
)
func Utf8ToGbk(text []byte) string {
r := bytes.NewReader(text)
decoder := transform.NewReader(r, simplifiedchinese.GBK.NewDecoder()) //GB18030
content, _ := ioutil.ReadAll(decoder)
return strings.ReplaceAll(string(content), string([]byte{0x00}), "")
}