RuneCount in Go

Posted by GoDoc
Public (Editable by Users)

RuneCount returns the number of runes in p. Erroneous and short encodings are treated as single runes of width 1 byte.

Go
Edit
package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	buf := []byte("Hello, 世界")
	fmt.Println("bytes =", len(buf))
	fmt.Println("runes =", utf8.RuneCount(buf))
}