-2
package main  
  
import ("fmt")

func main() {
    lenString: = len("САЛИХА ХАМЗЕЕВНА ГАРИПОВА САЛ ХА ХАМЗЕ ВНА ГАР ПОВА") fmt.Println(lenString)
}

Why the length of the string is returning 94 although the length is 51 of the mentioned string

Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46
  • 1
    `len` returns the number of bytes in the string, not the number of characters (runes). Use `utf8.RuneCountInString` to get the number of runes in a string. https://go.dev/play/p/Ecjdsd0bKzf – mkopriva May 15 '23 at 13:29

1 Answers1

0

As per documentation len method is counting number of bytes in string. Characters in your string are mostly utf-8 encoded. So one character up to 4 bytes: https://en.wikipedia.org/wiki/UTF-8. So one character is taking more then one byte in your string.

Here is online tool that can prove your results: https://mothereff.in/byte-counter

Ivan Vasiljevic
  • 5,478
  • 2
  • 30
  • 35