mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-23 07:22:16 +08:00
docs: unicode.Is 统计中文字符
This commit is contained in:
parent
3857cd6c72
commit
42dea29039
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -41,6 +42,15 @@ func main() {
|
|||||||
|
|
||||||
fmt.Printf("b1: []byte: %+v \t string: %s\n", b1, b1)
|
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("=========================================================")
|
fmt.Println("=========================================================")
|
||||||
|
|
||||||
// 多行字符串
|
// 多行字符串
|
||||||
|
Loading…
Reference in New Issue
Block a user