获取字符串的长度

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

 

例:

 

    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) 
posted @ 2016-12-29 16:56  赵客缦胡缨-Nicholas  阅读(216)  评论(0编辑  收藏  举报