Golang bytes.Buffer.WriteRune() function example

package bytes

WriteRune appends the UTF-8 encoding of Unicode code point input rune to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge.

Golang bytes.Buffer.WriteRune() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 buff := bytes.NewBuffer(nil) // create empty buffer

 n, err := buff.WriteRune('世')

 fmt.Printf("%s %d %v \n", string(buff.Bytes()), n, err)
 }

Output :

世 3 <nil>

Reference :

http://golang.org/pkg/bytes/#Buffer.WriteRune

Advertisement