美文网首页Go专题
常用函数记录

常用函数记录

作者: 右哼哼丨左哼哼 | 来源:发表于2019-05-08 22:09 被阅读0次

字符串编码转换函数:

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)
}

相关文章

网友评论

    本文标题:常用函数记录

    本文链接:https://www.haomeiwen.com/subject/rjsboqtx.html