Golang bytes.Buffer.ReadString() function example

package bytes

ReadString reads until the first occurrence of delimiter(1st parameter) in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delimiter.

Golang bytes.Buffer.ReadString() function usage

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 buff := bytes.NewBuffer([]byte("abcde#fg"))

 line, err := buff.ReadString('#')

 fmt.Println(line,err)

 }

Output :

abcde# <nil>

Reference :

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

Advertisement