Skip to content

Instantly share code, notes, and snippets.

@lmas
Created February 20, 2016 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmas/303b5b1667a0edf640ed to your computer and use it in GitHub Desktop.
Save lmas/303b5b1667a0edf640ed to your computer and use it in GitHub Desktop.
Decode Windows-1252 encoded strings.
package main
import (
"fmt"
"io/ioutil"
"strings"
"golang.org/x/text/encoding/charmap"
)
func main() {
sr := strings.NewReader("Gar\xe7on") // Some windows-1252 encoded string
tr := charmap.Windows1252.NewDecoder().Reader(sr)
b, e := ioutil.ReadAll(tr)
if e != nil {
fmt.Println("error:", e)
}
fmt.Println(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment