diff options
| author | jiahua wang <wjh180909@gmail.com> | 2021-09-24 10:07:44 +0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2021-09-27 16:30:23 +0000 |
| commit | 078247a4075650aa4eaf9b9e7fab3b4b70b27a5f (patch) | |
| tree | c8a20a4d229dfaa83f06bce1834863648a47e68e /src/bytes/example_test.go | |
| parent | d5cfba087f4947ac25714f925e610d0d3575d05e (diff) | |
| download | go-078247a4075650aa4eaf9b9e7fab3b4b70b27a5f.tar.xz | |
bytes: add example for (*Buffer).Next
Change-Id: Ic0a97fd7bb89865448e436e5c092415a29d8badf
Reviewed-on: https://go-review.googlesource.com/c/go/+/352009
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: David Chase <drchase@google.com>
Diffstat (limited to 'src/bytes/example_test.go')
| -rw-r--r-- | src/bytes/example_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/bytes/example_test.go b/src/bytes/example_test.go index ae93202b57..d0d4dd2c2d 100644 --- a/src/bytes/example_test.go +++ b/src/bytes/example_test.go @@ -54,6 +54,19 @@ func ExampleBuffer_Len() { // Output: 5 } +func ExampleBuffer_Next() { + var b bytes.Buffer + b.Grow(64) + b.Write([]byte("abcde")) + fmt.Printf("%s\n", string(b.Next(2))) + fmt.Printf("%s\n", string(b.Next(2))) + fmt.Printf("%s", string(b.Next(2))) + // Output: + // ab + // cd + // e +} + func ExampleCompare() { // Interpret Compare's result by comparing it to zero. var a, b []byte |
