Standard library / strings

strings.Count()

Counts non-overlapping occurrences. An empty separator counts decoded runes plus one. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func Count(s, substr string) int

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
substrstringSubstring to search for.

Return Value

int

Counts non-overlapping occurrences. An empty separator counts decoded runes plus one.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  fmt.Println(strings.Count("aaaa", "aa"))}
Go Reference