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 Golang : How to get username from email address
+8.6k Golang : Populate slice with sequential integers example
+5.7k Restart Apache or Nginx web server without password prompt
+7.9k Golang : Populate or initialize struct with values example
+13.1k Golang : Reset buffer example
+4.2k Python : Create Whois client or function example
+17.7k Golang : Calculate entire request body length during run time
+6.2k Golang : Use modern ciphers only in secure connection
+36.5k Golang : Comparing date or timestamp
+9.2k Golang : Allow Cross-Origin Resource Sharing request
+3.5k Java : Generate multiplication table example
+5.9k Golang : How to call function inside template with template.FuncMap