Golang bufio.UnreadByte() function example
package bufio
UnreadByte unreads the last byte. Only the most recently read byte can be unread.
Golang bufio.UnreadByte() function usage example
readbuffer := bytes.NewBuffer([]byte("abcde#fghijk"))
reader := bufio.NewReader(readbuffer)
before, _ := reader.ReadString('#') // # is the delimiter
fmt.Println(string(before))
reader.UnreadByte() // move the reader position back by 1 byte
after, _ := reader.ReadString('#')
fmt.Println(string(after))
Output :
abcde#
#
Advertisement
Something interesting
Tutorials
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+17.4k Golang : Multi threading or run two processes or more example
+9.1k Golang : Handle sub domain with Gin
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+5.6k Unix/Linux : How to find out the hard disk size?
+5k Linux : How to set root password in Linux Mint
+4.7k PHP : Extract part of a string starting from the middle
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+11.1k Golang : Web routing/multiplex example
+10.8k Golang : Natural string sorting example
+13.9k Golang : Human readable time elapsed format such as 5 days ago