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
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+10.9k Golang : Sieve of Eratosthenes algorithm
+6.8k Golang : Calculate pivot points for a cross
+6.7k Golang : Check if password length meet the requirement
+14.3k Golang : Get uploaded file name or access uploaded files
+9k Golang : Capture text return from exec function example
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+21.2k Golang : How to force compile or remove object files first before rebuild?
+10.7k Golang : Get currencies exchange rates example
+19.9k Golang : How to get time from unix nano example
+12.1k Golang : Save webcamera frames to video file
+12.5k Golang : HTTP response JSON encoded data