| 1 |
--- |
| 2 |
title: strings.Count |
| 3 |
description: Returns the number of non-overlapping instances of the given substring within the given string. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: int |
| 10 |
signatures: [strings.Count SUBSTR STRING] |
| 11 |
aliases: [/functions/strings.count] |
| 12 |
--- |
| 13 |
|
| 14 |
If `SUBSTR` is an empty string, this function returns 1 plus the number of Unicode [code points](g) in `STRING`. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ "aaabaab" | strings.Count "a" }} → 5 |
| 18 |
{{ "aaabaab" | strings.Count "aa" }} → 2 |
| 19 |
{{ "aaabaab" | strings.Count "aaa" }} → 1 |
| 20 |
{{ "aaabaab" | strings.Count "" }} → 8 |
| 21 |
``` |