[utf8说明](https://pkg.go.dev/unicode/utf8)

获取真实字符串大小

  1. package main
  2. import (
  3. "fmt"
  4. "unicode/utf8"
  5. )
  6. func main() {
  7. ch1 := "xiaolizi"
  8. ch2 := "李"
  9. ch3 := "l哥"
  10. fmt.Printf("字符串%v 字节大小or字符长度%d 真实字符长度%d\n", ch1, len(ch1), utf8.RuneCountInString(ch1))
  11. fmt.Printf("字符串%v 字节大小or字符长度%d 真实字符长度%d\n", ch2, len(ch2), utf8.RuneCountInString(ch2))
  12. fmt.Printf("字符串%v 字节大小or字符长度%d 真实字符长度%d\n", ch3, len(ch3), utf8.RuneCountInString(ch3))
  13. }