utf8 length

Fix the mistake below to assure the length of utf8 string can be printed correctly.

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. fmt.Println(len("你好"))
  7. }

Answer

  1. package main
  2. import (
  3. "fmt"
  4. "unicode/utf8"
  5. )
  6. func main() {
  7. fmt.Println(utf8.RuneCountInString("你好"))
  8. }