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.3k Golang : Embed secret text string into binary(executable) file
+15.6k Golang : Validate hostname
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+13.4k Golang : Verify token from Google Authenticator App
+14.8k Golang : Normalize unicode strings for comparison purpose
+7k Golang : constant 20013 overflows byte error message
+7.1k Golang : Get Alexa ranking data example
+39k Golang : How to iterate over a []string(array)
+7.6k Android Studio : AlertDialog to get user attention example
+13.6k Golang : Query string with space symbol %20 in between
+5k Google : Block or disable caching of your website content