Standard library / bufio
bufio.NewScanner()
Creates a token scanner using ScanLines by default. Check Err after Scan returns false. Expected stdout: 'a\nb\n'.
Formal Syntax & Structure
go syntaxgo
func NewScanner(r io.Reader) *ScannerParameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.Reader | Source reader. |
Return Value
*Scanner
Creates a token scanner using ScanLines by default.
Working Example
Example Snippetgo
package main
import ( "bufio" "fmt" "strings")
func main() { s := bufio.NewScanner(strings.NewReader("a\nb")) for s.Scan() { fmt.Println(s.Text()) } if s.Err() != nil { panic(s.Err()) }}