Junior — Middle
How can you determine the length of a string in characters in the Go language?
sobes.tech AI
Answer from AI
In Go, a string is a sequence of bytes, not Unicode characters. To get the length of a string in characters (runes), you need to convert the string to a slice of runes and measure its length:
s := "Привет"
length := len([]rune(s))
fmt.Println(length) // Will output the number of characters
Since one Unicode character can occupy multiple bytes, using len(s) will give the number of bytes, not characters.