Golang unicode/utf16.DecodeRune() function example
package unicode/utf16
Golang unicode/utf16.DecodeRune() function usage example.
DecodeRune returns the UTF-16 decoding of a surrogate pair. If the pair is not a valid UTF-16 surrogate pair, DecodeRune returns the Unicode replacement code point U+FFFD.
package main
import (
"fmt"
"unicode/utf16"
)
func main() {
valid_pair := utf16.DecodeRune(0xd800, 0xdc00)
fmt.Printf("%x \n", valid_pair)
not_valid_pair := utf16.DecodeRune('\u6C34', '水')
fmt.Printf("%x \n", not_valid_pair)
not_valid_pair = utf16.DecodeRune(0xd800, '爱')
fmt.Printf("%x \n", not_valid_pair)
}
Sample output :
10000
fffd
fffd
Reference :
Advertisement
Something interesting
Tutorials
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+4.4k Linux/MacOSX : Search and delete files by extension
+10.3k Golang : Detect number of faces or vehicles in a photo
+11.6k Swift : Convert (cast) Float to String
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+33.7k Golang : All update packages with go get command
+18.8k Golang : How to make function callback or pass value from function as parameter?
+6.7k Golang : Experimental emojis or emoticons icons programming language
+17.4k Golang : Multi threading or run two processes or more example
+7.4k Golang : Word limiter example
+29.5k Golang : Saving(serializing) and reading file with GOB
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example