Standard library / unicode/utf8

utf8.DecodeRuneInString()

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

Formal Syntax & Structure

go syntaxgo
func DecodeRuneInString(s string) (r rune, size int)

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.

Return Value

(r rune, size int)

Decodes the first rune and byte width from a string; empty input gives RuneError,0 and invalid nonempty input gives RuneError,1.

Working Example

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