Sobes.tech
Junior — Middle

How can you determine the number of characters in a Cyrillic string?

sobes.tech AI

Answer from AI

In Go, strings are sequences of bytes, and Unicode characters (including Cyrillic) can occupy multiple bytes. To determine the number of characters (runes) in a Cyrillic string, you need to convert the string into a slice of runes and take its length:

s := "Привет"
runes := []rune(s)
count := len(runes)
fmt.Println(count) // Will output 6

This way, we correctly count the characters themselves, not the bytes.

How can you determine the number of characters in a… - sobes.tech