Junior
How to determine the number of characters in a string?
sobes.tech AI
Answer from AI
Using the utf8.RuneCountInString() function from the unicode/utf8 package.
import (
"fmt"
"unicode/utf8"
)
func main() {
str := "Привет, мир!"
count := utf8.RuneCountInString(str) // Counts the number of runes (characters)
fmt.Println(count) // Output: 12
}