Standard library / strings

strings.Reader.UnreadByte()

Moves the byte cursor back one position; fails at the start. Do not assume repeated unreads are portable across io.ByteScanner implementations. Expected stdout: '<nil> 3\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) UnreadByte() error

Return Value

error

Moves the byte cursor back one position; fails at the start. Do not assume repeated unreads are portable across io.ByteScanner implementations.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  r := strings.NewReader("aé")  r.ReadByte()  e := r.UnreadByte()  fmt.Println(e, r.Len())}
Go Reference