Golang bytes.Buffer.NewBufferString() function example
package bytes
NewBufferString creates and initializes a new Buffer using the input string as its initial contents. It is intended to prepare a buffer to read an existing string.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
Golang bytes.NewBufferString() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
newbuf := bytes.NewBufferString("abcdefg") // just a string will do
var buff [7]byte
newbuf.Read(buff[:])
fmt.Println(string(buff[:]))
}
Output :
abcdefg
Reference :
Advertisement
Something interesting
Tutorials
+12.3k Golang : Get month name from date example
+13.8k Golang : unknown escape sequence error
+7.7k Golang : Command line ticker to show work in progress
+18.5k Golang : Set, Get and List environment variables
+13.8k Generate salted password with OpenSSL example
+12.7k Golang : zlib compress file example
+17.7k How to enable MariaDB/MySQL logs ?
+11.6k Android Studio : Create custom icons for your application example
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+5.2k Golang : Convert lines of string into list for delete and insert operation
+6.2k Golang : Extract XML attribute data with attr field tag example