[Golang] Calculate String Length


Calculate the length of string (UTF-8) in Go programming language. Iterate over the UTF-8 string by for or range keyword to calculate string length.

range iteration

Run Code on Go Playground

func StringLength(s string) int {
      l := 0
      for _, runeValue := range s {
              runeValue = runeValue
              l++
      }
      return l
}