1. - 使用 bytes.Count() 统计  
  2. - 使用 strings.Count() 统计  
  3. - 将字符串转换为 []rune 后调用 len 函数进行统计  
  4. - 使用 utf8.RuneCountInString() 统计  
获取字符串的长度

 

例:

 

[java] view plain copy
    1. str:="HelloWord"  
    2. l1:=len([]rune(str))  
    3. l2:=bytes.Count([]byte(str),nil)-1)  
    4. l3:=strings.Count(str,"")-1  
    5. l4:=utf8.RuneCountInString(str)  
    6. fmt.Println(l1) 

相关文章:

  • 2021-05-19
  • 2021-12-21
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案