mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
04.4.1.md
This commit is contained in:
17
eBook/examples/chapter_4/count_substring.go
Normal file
17
eBook/examples/chapter_4/count_substring.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var str string = "Hello, how is it going, Hugo?"
|
||||
var manyG = "gggggggggg"
|
||||
|
||||
fmt.Printf("Number of H's in %s is: ", str)
|
||||
fmt.Printf("%d\n", strings.Count(str, "H"))
|
||||
|
||||
fmt.Printf("Number of double g's in %s is: ", manyG)
|
||||
fmt.Printf("%d\n", strings.Count(manyG, "gg"))
|
||||
}
|
Reference in New Issue
Block a user