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
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+5.1k Linux : How to set root password in Linux Mint
+10.1k Golang : Print how to use flag for your application example
+12k Golang : Clean formatting/indenting or pretty print JSON result
+6k Golang : Compound interest over time example
+18.5k Golang : Write file with io.WriteString
+5.8k Golang : List all packages and search for certain package
+7.4k Golang : Individual and total number of words counter example
+6.5k Golang : Combine slices of complex numbers and operation example
+25.3k Golang : Get current file path of a file or executable
+11.3k Golang : How to use if, eq and print properly in html template