Standard library / bytes

bytes.Buffer.Next()

Returns up to n next unread bytes and advances the read position. Result aliases storage until the next read or write. Use nonnegative n. Expected stdout: 'go !\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Buffer) Next(n int) []byte

Parameters & Attributes

NameTypeDescription
nintMaximum unread byte count to consume; use a nonnegative value.

Return Value

[]byte

Returns up to n next unread bytes and advances the read position. Result aliases storage until the next read or write. Use nonnegative n.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  b := bytes.NewBufferString("go!")  fmt.Println(string(b.Next(2)), b.String())}
Go Reference