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.8k Golang : Delete duplicate items from a slice/array
+12.7k Golang : Remove or trim extra comma from CSV
+5.3k Javascript : Change page title to get viewer attention
+9.4k Golang : Find the length of big.Int variable example
+48.5k Golang : Upload file from web browser to server
+6.5k Unix/Linux : How to get own IP address ?
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+17.8k Golang : Defer function inside init()
+12.6k Golang : Exit, terminating or aborting a program
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+15.6k Golang : How to convert(cast) IP address to string?