Standard library / unicode/utf8

utf8.RuneLen()

Returns the UTF-8 byte width of a valid rune, or -1 for invalid code points. Expected stdout: '2 -1\n'.

Formal Syntax & Structure

go syntaxgo
func RuneLen(r rune) int

Parameters & Attributes

NameTypeDescription
rruneUnicode code point.

Return Value

int

Returns the UTF-8 byte width of a valid rune, or -1 for invalid code points.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf8")
func main() {  fmt.Println(utf8.RuneLen('é'), utf8.RuneLen(0xd800))}
Go Reference