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
+7.4k Golang : Word limiter example
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+22.2k Golang : Securing password with salt
+21.8k Golang : Convert string slice to struct and access with reflect example
+14.6k Golang : Convert(cast) int to float example
+11.6k Golang : Simple file scaning and remove virus example
+7.8k Swift : Convert (cast) String to Double
+12.7k Golang : zlib compress file example
+11.3k Golang : How to flush a channel before the end of program?
+6.7k Golang : Reverse by word
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+10.6k Golang : Get local time and equivalent time in different time zone