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
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+7.5k Golang : Gorrila set route name and get the current route name
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)
+5.9k Golang : Shuffle array of list
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+11.7k Golang : Find age or leap age from date of birth example
+23.5k Golang : Read a file into an array or slice example
+6.9k Golang : How to solve "too many .rsrc sections" error?
+36.5k Golang : Validate IP address
+10.7k Golang : Underscore string example
+14k Golang : Reverse IP address for reverse DNS lookup example
+10.3k Golang : Convert file unix timestamp to UTC time example