Created
January 12, 2018 07:04
-
-
Save sekky0905/5422bfe93e7e9982cd478cd805111627 to your computer and use it in GitHub Desktop.
Goで文字列の中の特定の文字列をカウントする(strings.Count) ref: https://qiita.com/Sekky0905/items/b022b5192b41d4a41e0f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "")) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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