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
+13k Golang : Calculate elapsed years or months since a date
+11k Golang : Create S3 bucket with official aws-sdk-go package
+14k Golang : concatenate(combine) strings
+15.3k Golang : Delete certain files in a directory
+10.6k Android Studio : Simple input textbox and intercept key example
+7.7k Golang : get the current working directory of a running program
+7.1k Golang : Squaring elements in array
+6.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+41.9k Golang : How do I convert int to uint8?
+19.8k Golang : Append content to a file
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+13k Golang : Get terminal width and height example