作者:kikokikolove | 来源:互联网 | 2023-10-10 10:08
Golang-unicode-对字符串中汉字数量进行统计unicode.Is()packagemainimport(fmtunicode)Han表示汉字,其它语言表达
//对字符串中汉字数量进行统计
//unicode.Is()
package main
import (
"fmt"
"unicode"
)
//Han表示汉字,其它语言表达可在字符集中查询
func main() {
a := "すごい,今天你pass了English考试"
count := 0
for _, v := range a {
if unicode.Is(unicode.Han, v) {
count++
}
}
fmt.Println(count)
}
运行结果:
6