O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter02/recipe08.
  2. Navigate to the directory.
  3. Create the file win1250.txt with content Gdańsk. The file must be encoded in the windows-1250 charset. If you are not sure how to do that, just jump to step 6 and after you complete step 7, which will create the windows-1250 encoded file, you can rename the out.txt file and go back to step 4.
  4. Create the decode.go file with the following content:
        package main        import (          "fmt"          "io/ioutil"          "os"          "strings"          "golang.org/x/text/encoding/charmap"        )        func main() {          // Open windows-1250 file.          f, err := os.Open("win1250.txt")          if err != nil {            panic(err)          }          defer f.Close()          // Read all in raw form.          b, err := ioutil.ReadAll(f)          if err != nil {            panic(err) } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required