Skip to content

Instantly share code, notes, and snippets.

@C0nstantin
Created May 27, 2015 12:40
Show Gist options
  • Save C0nstantin/d211b1dfaa18bc577b92 to your computer and use it in GitHub Desktop.
Save C0nstantin/d211b1dfaa18bc577b92 to your computer and use it in GitHub Desktop.
Go win1251 to utf8
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