Skip to content

Commit

Permalink
bufio: add example for Scanner.Bytes
Browse files Browse the repository at this point in the history
Change-Id: I4a5c7573e13dd85531ee9f4dd2a0d1981bf8cdfa
Reviewed-on: https://go-review.googlesource.com/c/go/+/51412
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
Guitarbum722 authored and ianlancetaylor committed Jun 21, 2019
1 parent 1130cc7 commit 44c9354
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/bufio/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func ExampleScanner_lines() {
}
}

// Use return the most recent call to Scan as a []byte
func ExampleScanner_Bytes() {
scanner := bufio.NewScanner(strings.NewReader("gopher"))
for scanner.Scan() {
fmt.Println(len(scanner.Bytes()) == 6)
}
// Output:
// true
}

// Use a Scanner to implement a simple word-count utility by scanning the
// input as a sequence of space-delimited tokens.
func ExampleScanner_words() {
Expand Down

0 comments on commit 44c9354

Please sign in to comment.