统计字符串每个字符出现次数!
package main import ( "fmt" ) func WordCount(s string) map[string]int { var word string m := make(map[string]int) for i := 0; i < len(s); { word = s[i : i+1] fmt.Println(word) v, ok := m[word] if ok != false { m[word] = v + 1 } else { m[word] = 1 } i += 1 } return m } func main() { var str = "stringsg" fmt.Println(WordCount(str)) }
有疑问加站长微信联系(非本文作者)