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
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+4.8k PHP : Extract part of a string starting from the middle
+16k Golang : Generate universally unique identifier(UUID) example
+9k Golang : Populate or initialize struct with values example
+10.8k Golang : Command line file upload program to server example
+13.9k Golang : Human readable time elapsed format such as 5 days ago
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+17.7k Golang : Read data from config file and assign to variables
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+13.4k Golang : Get constant name from value
+12k Golang : Decompress zlib file example