Go语言中文手册 · 解决中文乱码

admin 2024-08-15 16:35:21 编程 来源:ZONE.CI 全球网 0 阅读模式

1. 解决中文乱码

Go中实现的字符集转换库。

Mahonia是在Go中实现的字符集转换库。所有数据都被编译到可执行文件中;它不需要任何外部数据文件。

根据http://code.google.com/p/mahonia/

1.1.1. 安装

    go get github.com/axgle/mahonia

1.1.2. 小案例

package main

import "fmt"
import "github.com/axgle/mahonia"

func main() {
    enc := mahonia.NewEncoder("gbk")
    //converts a  string from UTF-8 to gbk encoding.
    fmt.Println(enc.ConvertString("hello,世界"))
}
weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论:0   参与:  0