Skip to content

Instantly share code, notes, and snippets.

@sekky0905
Created January 12, 2018 07:04
Show Gist options
  • Save sekky0905/5422bfe93e7e9982cd478cd805111627 to your computer and use it in GitHub Desktop.
Save sekky0905/5422bfe93e7e9982cd478cd805111627 to your computer and use it in GitHub Desktop.
Goで文字列の中の特定の文字列をカウントする(strings.Count) ref: https://qiita.com/Sekky0905/items/b022b5192b41d4a41e0f
package main
import (
"fmt"
"strings"
)
func main() {
str := "aaabbbcc"
// 普通に表示
fmt.Printf("str : %s\n", str)
// cを数える
fmt.Printf("count of \"c\" : %d\n", strings.Count(str, "c"))
// 空文字で数えてみる
fmt.Printf("count of \"\" : %d\n", strings.Count(str, ""))
}
str : aaabbbcc
count of "c" : 2
count of "" : 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment