Created
May 27, 2015 12:40
-
-
Save C0nstantin/d211b1dfaa18bc577b92 to your computer and use it in GitHub Desktop.
Go win1251 to utf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import( | |
| "code.google.com/p/go.text/transform" | |
| "code.google.com/p/go.text/encoding/charmap" | |
| ) | |
| func toutf8(str string) string { | |
| sr := strings.NewReader(str) | |
| tr := transform.NewReader(sr, charmap.Windows1251.NewDecoder()) | |
| buf, err := ioutil.ReadAll(tr) | |
| if err != nil { | |
| // обработка ошибки | |
| } | |
| s := string(buf) //text в utf8 | |
| return s; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment