Standard library / unicode/utf8

utf8.RuneCountInString()

Counts decoded runes in a string; each invalid byte counts as one error rune, not a visible character count. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func RuneCountInString(s string) (n int)

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.

Return Value

(n int)

Counts decoded runes in a string; each invalid byte counts as one error rune, not a visible character count.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf8")
func main() {  fmt.Println(utf8.RuneCountInString("e\u0301"))}
Go Reference