Standard library / strings

strings.Reader.Seek()

Changes byte position relative to start, current cursor or end. Negative resulting offsets and invalid whence fail; seeking beyond end is allowed. Expected stdout: '1 <nil> 2\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) Seek(offset int64, whence int) (int64, error)

Parameters & Attributes

NameTypeDescription
offsetint64Signed byte displacement relative to whence.
whenceintOrigin: io.SeekStart, io.SeekCurrent or io.SeekEnd.

Return Value

(int64, error)

Changes byte position relative to start, current cursor or end. Negative resulting offsets and invalid whence fail; seeking beyond end is allowed.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "strings")
func main() {  r := strings.NewReader("aé")  pos, e := r.Seek(-2, io.SeekEnd)  fmt.Println(pos, e, r.Len())}
Go Reference