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
+11k How to test Facebook App on localhost ?
+3.4k Golang : Fix go-cron set time not working issue
+33.7k Golang : All update packages with go get command
+10k Golang : Setting variable value with ldflags
+7.4k Android Studio : How to detect camera, activate and capture example
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+5.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+6.7k Golang : Skip or discard items of non-interest when iterating example
+10.3k Golang : Embed secret text string into binary(executable) file
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error