go 学习01

go语言 用go统计字符串中汉字的数量

import (
	"fmt" 
)
func main() {
  a := 0
	s1 := "hello沙河小王子"
	for _, i := range s1 {
		if unicode.Is(unicode.Han,c) {
			a ++
		}
	}
	fmt.Println(a)
}//终端中运行 代码自动整理 go fmt main.go  
posted @ 2021-06-21 11:22  ZY98  阅读(35)  评论(0编辑  收藏  举报