Golang bytes.Buffer.WriteString() function example
package bytes
WriteString appends the contents of the input string to the buffer, growing the buffer as needed. The return value n is the length of the input string; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge.
Golang bytes.Buffer.WriteString() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBuffer(nil) // create empty buffer
n, err := buff.WriteString("Hello World! = 你好世界!")
fmt.Printf("%s %d %v \n", string(buff.Bytes()), n, err)
}
Output :
Hello World! = 你好世界! 28 <nil>
Reference :
Advertisement
Something interesting
Tutorials
+6.7k Golang : Skip or discard items of non-interest when iterating example
+25.5k Golang : Generate MD5 checksum of a file
+6.6k Golang : How to validate ISBN?
+21.1k Golang : For loop continue,break and range
+5.9k Golang : Generate multiplication table from an integer example
+19.2k Golang : Delete item from slice based on index/key position
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+7.9k Javascript : Put image into Chrome browser's console
+9.7k PHP : Get coordinates latitude/longitude from string
+6.7k Golang : Output or print out JSON stream/encoded data
+6.3k Golang : Test input string for unicode example
+17.7k Golang : [json: cannot unmarshal object into Go value of type]