docs: unicode.Is 统计中文字符

This commit is contained in:
Shikong 2021-09-13 23:53:07 +08:00
parent 3857cd6c72
commit 42dea29039

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"strings"
"unicode"
)
func main() {
@ -41,6 +42,15 @@ func main() {
fmt.Printf("b1: []byte: %+v \t string: %s\n", b1, b1)
// 统计字符串中 中文字符数量
var count int
for _, char := range s2 {
if unicode.Is(unicode.Han, char) {
count++
}
}
fmt.Printf("%s 汉字数量 => %d\n", s2, count)
fmt.Println("=========================================================")
// 多行字符串