Golang bytes.Buffer.String() function example

package bytes

String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".

Golang bytes.Buffer.String() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 buff := bytes.NewBuffer([]byte("abcdefg"))

 fmt.Println(buff.String())

 var buf *bytes.Buffer  // pointer

 fmt.Println(buf.String())
 }

Output :

abcdefg

<nil>

Reference :

http://golang.org/pkg/bytes/#Buffer.String

Advertisement