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
+17.9k Golang : Qt image viewer example
+17.1k Golang : XML to JSON example
+7.1k Golang : Array mapping with Interface
+13.8k Golang : Gin framework accept query string by post request example
+33k Golang : How to check if a date is within certain range?
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+12.1k Golang : Pagination with go-paginator configuration example
+25.9k Golang : How to read integer value from standard input ?
+11.9k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+8k Golang : Sort words with first uppercase letter
+7.8k Swift : Convert (cast) String to Double
+10.5k Swift : Convert (cast) String to Integer