Skip to content

xgfone/go-encode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-encode

Convert the string between the charsets.

Charsets

It supports the common charset encoding. See Charset.

Notice:

You need using the alias of the charset.

Installation

$ go get -u github.com/xgfone/go-encode

Example

package main

import (
    "fmt"

    "github.com/xgfone/go-encode"
)

func main() {
    gbk := string([]byte{'\xd6', '\xd0', '\xb9', '\xfa'})

    // Convert the string from GBK to UTF8
    if utf8, err := encode.ToUtf8("gbk", gbk); err == nil {
        fmt.Printf("%v\n", utf8) // 中国
    }

    // Convert the string from GBK to UTF8
    if utf8, err := encode.Convert("gbk", "utf8", gbk); err == nil {
        fmt.Printf("%v\n", utf8) // 中国
    }

    // Convert the string from UTF8 to GBK
    if _gbk, err := encode.FromUtf8("gbk", "中国"); err == nil {
        fmt.Printf("%x\n", _gbk) // d6d0b9fa
    }
}

About

Convert the string between the charsets.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages