Golang bufio.ReadRune() function example
package bufio
ReadRune reads a single UTF-8 encoded Unicode character and returns the rune and its size in bytes. If the encoded rune is invalid, it consumes one byte and returns unicode.ReplacementChar (U+FFFD) with a size of 1.
Golang bufio.ReadRune() function usage example
utf8buf := []byte("世界")
readbuffer := bytes.NewBuffer(utf8buf)
reader := bufio.NewReader(readbuffer)
rune, size, err := reader.ReadRune()
if err == nil {
fmt.Println(string(rune))
fmt.Printf("%x, %d\n", rune, size)
fmt.Printf("%x\n", utf8buf[:size])
}
output :
世
4e16, 3
e4b896
Advertisement
Something interesting
Tutorials
+12.4k Golang : Search and extract certain XML data example
+7k Web : How to see your website from different countries?
+48.1k Golang : How to convert JSON string to map and slice
+10k Golang : Setting variable value with ldflags
+8.4k PHP : How to parse ElasticSearch JSON ?
+14.5k Golang : How to check if your program is running in a terminal
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+6.2k PHP : Get client IP address
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+14.5k Golang : Overwrite previous output with count down timer