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

     1  package main
     2  
     3  import (
     4  	"bufio"
     5  	"fmt"
     6  	"strings"
     7  )
     8  
     9  func main() {
    10  	s := strings.NewReader("ABC\nDEF\r\nGHI\nJKL")
    11  	bs := bufio.NewScanner(s)
    12  	for bs.Scan() {
    13  		fmt.Printf("%s %v\n", bs.Bytes(), bs.Text())
    14  	}
    15  }
    16  
    17  /*
    18  output
    19  ABC ABC
    20  DEF DEF
    21  GHI GHI
    22  JKL JKL
    23  */