Standard library / unicode/utf16
utf16.Encode()
Converts runes to UTF-16 code units, replacing invalid scalar values. Does not serialize byte order or insert a BOM. Expected stdout: '[0041 d83d de00]\n'.
Formal Syntax & Structure
go syntaxgo
func Encode(s []rune) []uint16Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []rune | Input Unicode code points to encode. |
Return Value
[]uint16
Converts runes to UTF-16 code units, replacing invalid scalar values. Does not serialize byte order or insert a BOM.
Working Example
Example Snippetgo
package main
import ( "fmt" "unicode/utf16")
func main() { fmt.Printf("%04x\n", utf16.Encode([]rune("A😀")))}