This commit is contained in:
bense
2022-05-08 22:41:43 +08:00
parent bd44e60cf4
commit ab01ec7539
10 changed files with 530 additions and 0 deletions

20
utils/strings.go Normal file
View File

@@ -0,0 +1,20 @@
package utils
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}), "")
}