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 :
Advertisement
Something interesting
Tutorials
+36.3k Golang : How to split or chunking a file to smaller pieces?
+8.4k Golang : Convert word to its plural form example
+9.2k Golang : How to control fmt or log print format?
+19.4k Golang : Fix cannot download, $GOPATH not set error
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+28.6k Golang : Read, Write(Create) and Delete Cookie example
+17.9k Golang : Login and logout a user after password verification and redirect example
+13.6k Golang : Set image canvas or background to transparent
+6k PHP : How to check if an array is empty ?
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+10.8k PHP : Convert(cast) bigInt to string
+8k Golang : Handle Palindrome string with case sensitivity and unicode