To count the number of times a smaller string occurs in a bigger string, use the Count function:
package main //from w w w .j a va 2 s.co m import ( "fmt" "strings" ) func main() { // func Count(s, sep string) int fmt.Println(strings.Count("test", "t")) // => 2 }
More examples
package main /*from w ww . j a v a 2 s. co m*/ import ( "fmt" "strings" ) func main() { fmt.Println(strings.Count("css", "s")) }