1 Star 0 Fork 0

muyouking / GoTools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SyncFi.go 999 Bytes
一键复制 编辑 原始数据 按行查看 历史
muyouking 提交于 2020-07-23 14:04 . 更新 H—_ReadLine 的转码方式
package Tools
//其它工具类
//md5,中文转码
import (
"bufio"
"crypto/md5"
// "hash/crc32"
"fmt"
"io"
"os"
"github.com/axgle/mahonia"
)
//生成并返回Md5码
func Md5sum3(file string) string {
f, err := os.Open(file)
if err != nil {
return ""
}
defer f.Close()
r := bufio.NewReader(f)
h := md5.New()
_, err = io.Copy(h, r)
if err != nil {
return ""
}
return fmt.Sprintf("%x", h.Sum(nil))
}
//处理中文字符串的方法
func EncoderGBK(str string) string {
return mahonia.NewEncoder("gbk").ConvertString(str)
}
//mahonia.NewEncoder 编码
//一般如果要处理的字符串有中文而程序显示乱码,使用这个将字符串转换一下
func EncoderUTF8(str string) string {
return mahonia.NewEncoder("UTF-8").ConvertString(str)
}
//mahonia.NewDecoder 解码
func DecoderGBK(str string) string {
return mahonia.NewDecoder("gbk").ConvertString(str)
}
func DecoderUTF8(str string) string {
return mahonia.NewDecoder("UTF-8").ConvertString(str)
}
Go
1
https://gitee.com/muyouking/GoTools.git
git@gitee.com:muyouking/GoTools.git
muyouking
GoTools
GoTools
master

搜索帮助