Golang unicode/utf16.Encode() function example
package unicode/utf16
Golang unicode/utf16.Encode() function usage example.
package main
import (
"fmt"
"unicode/utf16"
)
func main() {
rune_array := []rune{'a', 'b', '好', 0xfffd}
var uint16_array []uint16
uint16_array = utf16.Encode(rune_array)
fmt.Println(uint16_array)
// 0xfffd should not be encoded.
for _, item := range uint16_array {
fmt.Printf("0x%x \n", item)
}
}
Sample output :
[97 98 22909 65533]
0x61
0x62
0x597d
0xfffd
Reference :
Advertisement
Something interesting
Tutorials
+7.9k Javascript : How to check a browser's Do Not Track status?
+30k Golang : Get time.Duration in year, month, week or day
+14k Golang : Compress and decompress file with compress/flate example
+12.8k Golang : http.Get example
+11.4k Golang : Delay or limit HTTP requests example
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+32.5k Golang : Copy directory - including sub-directories and files
+11.6k Golang : Concurrency and goroutine example
+9.4k Golang : Create unique title slugs example
+14.4k Golang : How to pass map to html template and access the map's elements
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example