go []rune(chinese) 和utf8.RuneCountInString(chinese) 查询含中文的字符串长度

func main(){	
    var chinese = "我是中国人, I am Chinese"
    fmt.Println("chinese length", len(chinese))
    fmt.Println("chinese word length", len([]rune(chinese)))
    fmt.Println("chinese word length", utf8.RuneCountInString(chinese))
}

输出:

chinese length 31
chinese word length 19
chinese word length 19
posted @ 2022-04-27 21:26  ty1539  阅读(57)  评论(0编辑  收藏  举报