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
+10.9k Golang : How to transmit update file to client by HTTP request example
+5.3k Python : Convert(cast) string to bytes example
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+12.6k Golang : flag provided but not defined error
+9.7k Random number generation with crypto/rand in Go
+24k Golang : Call function from another package
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+5.3k Golang : Get FX sentiment from website example
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+7.5k Gogland : Single File versus Go Application Run Configurations
+5.3k PHP : Hide PHP version information from curl