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
+17k Golang : How to save log messages to file?
+15.3k nginx: [emerg] unknown directive "ssl"
+29.3k Golang : Save map/struct to JSON or XML file
+10.1k Golang : Compare files modify date example
+5.7k List of Golang XML tutorials
+14.5k Golang : How to determine if user agent is a mobile device example
+7.9k Javascript : Put image into Chrome browser's console
+9.9k Golang : Function wrapper that takes arguments and return result example
+8.4k Golang : Convert word to its plural form example
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+12.6k Golang : Exit, terminating or aborting a program
+16.1k Golang : How to check if input from os.Args is integer?