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
+13.5k Golang : Count number of runes in string
+11.6k Golang : Convert(cast) float to int
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+6.3k Golang : Selection sort example
+13.2k Golang : Convert(cast) int to int64
+8.7k Golang : Combine slices but preserve order example
+6k Fontello : How to load and use fonts?
+19.2k Golang : Execute shell command
+22.9k Golang : Gorilla mux routing example
+19.5k Golang : How to Set or Add Header http.ResponseWriter?
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example