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
+7.9k Swift : Convert (cast) String to Float
+6.3k Golang : Selection sort example
+22.1k Golang : Repeat a character by multiple of x factor
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+19.1k Mac OSX : Homebrew and Golang
+8.5k Golang : How to check if input string is a word?
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+11.9k Golang : Convert(cast) bigint to string
+12.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+5.3k Golang : Get FX sentiment from website example