Standard library / unicode/utf8

utf8.DecodeRune()

Decodes the first rune and byte width. Empty input gives RuneError,0; invalid nonempty input gives RuneError,1. Expected stdout: 'é 2\n'.

Formal Syntax & Structure

go syntaxgo
func DecodeRune(p []byte) (r rune, size int)

Parameters & Attributes

NameTypeDescription
p[]byteByte sequence or destination buffer, as specified.

Return Value

(r rune, size int)

Decodes the first rune and byte width. Empty input gives RuneError,0; invalid nonempty input gives RuneError,1.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf8")
func main() {  r, n := utf8.DecodeRune([]byte("é!"))  fmt.Println(string(r), n)}
Go Reference