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
+4.4k Javascript : How to loop over and parse JSON data?
+4k Golang : Convert lines of string into list for delete and insert operation
+31.2k Golang : How to check if a date is within certain range?
+13.7k Golang : Get all local users and print out their home directory, description and group id
+4.7k Swift : Get substring with rangeOfString() function example
+13.1k Golang : How to get URL port?
+12.8k Golang : Simple word wrap or line breaking example
+8.1k Golang : Generate Codabar
+13.1k Golang : GUI with Qt and OpenCV to capture image from camera
+17.2k Golang : Write file with io.WriteString
+32.4k Golang : Call a function after some delay(time.Sleep and Tick)
+15.9k Golang : Check if IP address is version 4 or 6