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.1k Golang : Serving HTTP and Websocket from different ports in a program example
+33k Golang : How to check if a date is within certain range?
+8.1k Golang : Tell color name with OpenCV example
+5.3k Javascript : Shuffle or randomize array example
+9.6k Golang : Validate IPv6 example
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+7.3k Golang : alternative to os.Exit() function
+6.3k Golang : Detect face in uploaded photo like GPlus
+8.6k Golang : Set or add headers for many or different handlers
+18.6k Golang : Generate thumbnails from images
+10.6k Golang : Simple File Server
+24.5k Golang : How to validate URL the right way