Standard library / unicode/utf16

utf16.RuneLen()

Returns the number of UTF-16 code units for a valid scalar, or -1 if invalid. Expected stdout: '1 2 -1\n'.

Formal Syntax & Structure

go syntaxgo
func RuneLen(r rune) int

Parameters & Attributes

NameTypeDescription
rruneUnicode code point.

Return Value

int

Returns the number of UTF-16 code units for a valid scalar, or -1 if invalid.

Working Example

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