Golang bytes.Buffer.Next() function example
package bytes
Next returns a slice containing the next n (1st parameter) bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
Golang bytes.Buffer.Next() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBufferString("abcdefghi")
var threebytes [3]byte
buff.Read(threebytes[0:3])
fmt.Printf("%s\n", string(threebytes[:]))
// read the next 5 bytes
fmt.Printf("%s\n", string(buff.Next(5)))
}
Output :
abc
defgh
Reference :
Advertisement
Something interesting
Tutorials
+29.1k Golang : Get first few and last few characters from string
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+5.5k Golang : Display advertisement images or strings on random order
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+6.3k Golang : Test input string for unicode example
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+8.3k Golang : Auto-generate reply email with text/template package
+6.2k Golang & Javascript : How to save cropped image to file on server
+10.2k Golang : Check a web page existence with HEAD request example
+19.4k Golang : How to count the number of repeated characters in a string?
+6.3k Golang : Detect face in uploaded photo like GPlus
+5k Google : Block or disable caching of your website content