Golang bytes.Buffer.Reset() function example
package bytes
Reset resets the buffer so it has no content. Buffer.Reset() is the same as Buffer.Truncate(0).
Golang bytes.Buffer.Reset() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBuffer([]byte("abcdefg"))
fmt.Printf("%d \n", buff.Len())
// remove all content from the buff buffer
buff.Reset()
fmt.Printf("%d \n", buff.Len())
}
Output :
7
0
Reference :
Advertisement
Something interesting
Tutorials
+17.5k Golang : Find smallest number in array
+10.3k Golang : Embed secret text string into binary(executable) file
+9.2k Golang : How to control fmt or log print format?
+7k Golang : Levenshtein distance example
+25.3k Golang : Get current file path of a file or executable
+10.9k Golang : Sieve of Eratosthenes algorithm
+12.7k Golang : Sort and reverse sort a slice of bytes
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+11.8k Golang : convert(cast) float to string
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+17.7k Golang : Read data from config file and assign to variables
+21.1k Golang : Sort and reverse sort a slice of strings