package main
import (
"fmt"
"unicode")
// HanCounter to count the number of chinese character.
func HanCounter(s string) int {
var count int // 0
for _, c := range s {
if unicode.Is(unicode.Han, c) {
count++
}
}
return count
}
func main() {
s := "hello庫珀"
count := HanCounter(s)
fmt.Println(count)
}
一開始出現標黃exported function HanCounter should have comment or be unexported,需要在給函數添加註釋,且以函數名開頭,以句號結尾。