github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/coding/bufio/02-scan-with-split.go (about)

     1  package main
     2  
     3  import (
     4  	"bufio"
     5  	"fmt"
     6  	"strings"
     7  )
     8  
     9  func main() {
    10  	s := strings.NewReader("ABC DEF GHI JKL")
    11  	bs := bufio.NewScanner(s)
    12  	bs.Split(bufio.ScanWords)
    13  	for bs.Scan() {
    14  		fmt.Println(bs.Text())
    15  	}
    16  }
    17  
    18  /*
    19  output
    20  ABC
    21  DEF
    22  GHI
    23  JKL
    24  */