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 : Check if password length meet the requirement
+51.4k Golang : Check if item is in slice/array
+18.6k Golang : Generate thumbnails from images
+7.3k Golang : Not able to grep log.Println() output
+21.1k Golang : Get password from console input without echo or masked
+3.7k Golang : Switch Redis database redis.NewClient
+9.3k Golang : How to protect your source code from client, hosting company or hacker?
+7.7k Golang : Test if an input is an Armstrong number example
+23.5k Golang : Read a file into an array or slice example
+6.6k Golang : Embedded or data bundling example
+13.4k Golang : Increment string example
+29.5k Golang : How to create new XML file ?