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
+18.4k Golang : How to remove certain lines from a file
+26.8k Golang : Convert file content into array of bytes
+17k Golang : Get input from keyboard
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+8.7k Golang : Combine slices but preserve order example
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+4.4k Linux/MacOSX : Search and delete files by extension
+12.1k Golang : md5 hash of a string
+6k Golang : How to verify input is rune?
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+17k Golang : Get number of CPU cores