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
+21.6k Golang : Encrypt and decrypt data with TripleDES
+12.2k Golang : Detect user location with HTML5 geo-location
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+9.4k Android Studio : Indicate progression with ProgressBar example
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+5.4k Golang *File points to a file or directory ?
+11.8k Golang : Verify Linux user password again before executing a program example
+13.6k Android Studio : Password input and reveal password example
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+14k Golang : Compress and decompress file with compress/flate example
+8.9k Golang : Sort lines of text example