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
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+22.9k Golang : Test file read write permission example
+4.6k Mac OSX : Get disk partitions' size, type and name
+9.2k Golang : does not implement flag.Value (missing Set method)
+6.8k Golang : Calculate pivot points for a cross
+18.4k Golang : How to get hour, minute, second from time?
+8.1k Golang : Randomize letters from a string example
+19.1k Mac OSX : Homebrew and Golang
+36.4k Golang : Convert date or time stamp from string to time.Time type
+13.5k Golang : How to get year, month and day?
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example