Golang bufio.WriteString() function example
package bufio
WriteString writes a string. It returns the number of bytes written and it also returns an error if something goes wrong.
Golang bufio.WriteString() function usage example
package main
import (
"bufio"
"bytes"
"fmt"
)
func main() {
writebuffer := bytes.NewBuffer(nil)
writer := bufio.NewWriter(writebuffer)
num_bytes, _ := writer.WriteString("what is your 妈妈's maiden name?") // ignore the error, but you can put in error handler if you want
writer.Flush()
fmt.Println(string(writebuffer.Bytes()))
fmt.Printf("string has %d bytes\n", num_bytes)
}
Output :
what is your 妈妈's maiden name?
string has 34 bytes
Reference :
Advertisement
Something interesting
Tutorials
+18.6k Golang : Get download file size
+15.2k Golang : Accurate and reliable decimal calculations
+9.1k Golang : How to capture return values from goroutines?
+8.2k Golang : Qt splash screen with delay example
+24.6k Golang : How to validate URL the right way
+13k Swift : Convert (cast) Int to String ?
+5.6k PHP : Convert CSV to JSON with YQL example
+15.2k Golang : Save(pipe) HTTP response into a file
+12.1k Golang : convert(cast) string to integer value
+22.8k Golang : untar or extract tar ball archive example
+10.3k Golang : How to check if a website is served via HTTPS
+5.3k Javascript : Change page title to get viewer attention