Golang bytes.Reader.UnreadRune() function example
package bytes
Unread 1 rune from the reader current position.
Golang bytes.Reader.UnreadRune() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
reader := bytes.NewReader([]byte("我爱你"))
var r1,r2,r3 rune
r1,_, err := reader.ReadRune() // read 1 rune
fmt.Printf("%v %s \n", err, string(r1))
r2,_, err2 := reader.ReadRune() // read 1 rune
fmt.Printf("%v %s \n", err2, string(r2))
//unread 1 rune
reader.UnreadRune()
r3,_, err3 := reader.ReadRune() // read 1 rune
fmt.Printf("%v %s \n", err3, string(r3))
}
Output :
<nil> 我
<nil> 爱
<nil> 爱
Reference :
Advertisement
Something interesting
Tutorials
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+24.5k Golang : How to validate URL the right way
+27.2k Golang : Find files by name - cross platform example
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+8.9k Golang : Gaussian blur on image and camera video feed examples
+22.9k Golang : Gorilla mux routing example
+8.4k Golang : Convert word to its plural form example
+6.7k Golang : Output or print out JSON stream/encoded data
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+15.2k Golang : Get timezone offset from date or timestamp
+9.3k Golang : Timeout example