编辑代码

package main
import "fmt"

func countChars(str string) (int, int, int, int){
    var letters, digits, spaces, others int
    for _, ch := range str {
        switch{
            case unicode.IsLetter(ch):
            letters++
            case unicode.IsDigit(ch):
            digits++
            case unicode.IsSpace(ch):
            others++
        }
    }
    return letters, digits, spaces, others
}

func main () {
    srt := "hello, 世界!666"
    letters, digits, spaces, others := countChars(str)
    fmt.Printf("Letters: %d\nDigits: %d\nSpaces: %d\nDthers: %d\n",letters, digits, spaces, others)
}