Created
February 20, 2016 19:04
-
-
Save lmas/303b5b1667a0edf640ed to your computer and use it in GitHub Desktop.
Decode Windows-1252 encoded strings.
This file contains 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
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