package main
import (
"fmt"
"strings"
)
func main() {
str := "I love dba work I love my go work too I I I I"
m1 := make(map[string]int)
for _, v := range strings.Fields(str) {
if _, ok := m1[v]; ok {
m1[v] = m1[v] + 1
} else {
m1[v] = 1
}
}
//fmt.Println(m1)
for key, value := range m1 {
fmt.Printf("%q:%d\n", key, value)
}
}
有疑问加站长微信联系(非本文作者)