https://github.com/xgfone/go-encode
Convert the string between the charsets.
https://github.com/xgfone/go-encode
encode go golang
Last synced: 6 months ago
JSON representation
Convert the string between the charsets.
- Host: GitHub
- URL: https://github.com/xgfone/go-encode
- Owner: xgfone
- License: apache-2.0
- Created: 2016-04-02T11:53:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-11-30T04:10:04.000Z (almost 3 years ago)
- Last Synced: 2025-01-31T08:43:49.964Z (8 months ago)
- Topics: encode, go, golang
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-encode
Convert the string between the charsets.## Charsets
It supports the common charset encoding. See [Charset](./charsets.md).**Notice:**
You need using the alias of the charset.
## Installation
```shell
$ go get -u github.com/xgfone/go-encode
```## Example
```go
package mainimport (
"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
}
}
```