字符串编码转换函数:
import (
"github.com/axgle/mahonia"
)
func UseNewEncoder(src string,oldEncoder string,newEncoder string) string{
srcDecoder := mahonia.NewDecoder(oldEncoder)
desDecoder := mahonia.NewDecoder(newEncoder)
resStr:= srcDecoder.ConvertString(src)
_, resBytes, _ := desDecoder .Translate([]byte(resStr), true)
return string(resBytes)
}
网友评论