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) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| substr | string | Substring 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"))}