Standard library / unicode/utf16

utf16.Decode()

Converts UTF-16 code units to runes, replacing unpaired surrogates with U+FFFD. Input is code units, not encoded bytes. Expected stdout: '[U+1F600 U+FFFD]\n'.

Formal Syntax & Structure

go syntaxgo
func Decode(s []uint16) []rune

Parameters & Attributes

NameTypeDescription
s[]uint16Input UTF-16 code units to decode.

Return Value

[]rune

Converts UTF-16 code units to runes, replacing unpaired surrogates with U+FFFD. Input is code units, not encoded bytes.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf16")
func main() {  fmt.Printf("%U\n", utf16.Decode([]uint16{0xd83d, 0xde00, 0xd800}))}
Go Reference