Standard library / bytes

bytes.Buffer.Truncate()

Retains first n unread bytes and discards the rest. Panics for n outside zero through Len. Expected stdout: 'go\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Buffer) Truncate(n int)

Parameters & Attributes

NameTypeDescription
nintNumber of unread bytes to retain, from zero through Len.

Working Example

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