Strings In Depth7 / 17
Up next

Fields splits on whitespace

package main

import (
	"fmt"
	"strings"
)

func main() {
	text := "  the   quick  brown fox "
	// Fields splits on runs of whitespace
	words := strings.Fields(text)
	fmt.Println(len(words), words)
}
What you're solving

tokenize words, dropping empties