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/recipe02.
  2. Navigate to the directory.
  3. Create the whitespace.go file with the following content:
        package main        import (          "fmt"          "strings"        )        const refString = "Mary had a little lamb"         func main() {          words := strings.Fields(refString)          for idx, word := range words {            fmt.Printf("Word %d is: %s\n", idx, word)          }        }
  1. Run the code by executing go run whitespace.go.
  2. See the output in the Terminal:
  1. Create another file called anyother.go with the following content:
        package main        import (          "fmt"          "strings"        )        const refString = "Mary_had a little_lamb"        func main() { words := strings.Split(refString, ...

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