go-iconv: libiconv for go
Table of Contents
|
Summary
go-iconv is a libiconv wrapper for go. libiconv Convert string to requested character encoding.
go-iconv project's homepage is: https://github.com/xushiwei/go-iconv
Install
git clone git://github.com/xushiwei/go-iconv.git
cd go-iconv
make install
Example
Convert string
import ( "fmt" "xushiwei.com/iconv" ) func main() { cd, err := iconv.Open("gbk", "utf-8") if err != nil { fmt.Println("iconv.Open failed!") return } defer cd.Close() gbk := cd.ConvString("你好,世界!") fmt.Println(gbk) }
Output to io.Writer
import ( "fmt" "xushiwei.com/iconv" ) func main() { cd, err := iconv.Open("gbk", "utf-8") if err != nil { fmt.Println("iconv.Open failed!") return } defer cd.Close() output := ... // eg. output := os.Stdout || ouput, err := os.Create(file) autoSync := false // buffered or not bufSize := 0 // default if zero w := iconv.NewWriter(cd, output, bufSize, autoSync) fmt.Fprintln(w, "你好,世界!") w.Sync() // if autoSync = false, you need call Sync() by yourself }
Input from io.Reader
import ( "fmt" "io" "os" "xushiwei.com/iconv" ) func main() { cd, err := iconv.Open("utf-8", "gbk") // gbk => utf8 if err != nil { fmt.Println("iconv.Open failed!") return } defer cd.Close() input := ... // eg. input := os.Stdin || input, err := os.Open(file) bufSize := 0 // default if zero r := iconv.NewReader(cd, input, bufSize) _, err = io.Copy(os.Stdout, r) if err != nil { fmt.Println("\nio.Copy failed:", err) return } }
page revision: 7, last edited: 15 Jul 2011 08:07
windows下安装有错误
老兄,这个库可否更新一下,现在正需要用这个,谢谢。
我还买了你的书,最近正在看。
到底还更新不了?说话不算话哩
windows下要怎么安装呢?win没有make
Post preview:
Close preview