strings.Count.md (729B)
1 ---
2 title: strings.Count
3 description: Returns the number of non-overlapping instances of a substring within a string.
4 date: 2020-09-07
5 publishdate: 2020-09-07
6 lastmod: 2020-09-07
7 categories: [functions]
8 menu:
9 docs:
10 parent: "functions"
11 keywords: [count, counting, character count]
12 signature: ["strings.Count SUBSTR STRING"]
13 workson: []
14 hugoversion:
15 relatedfuncs: []
16 deprecated: false
17 aliases: []
18 ---
19
20 {{< new-in "0.74.0" >}}
21
22 If `SUBSTR` is an empty string, this function returns 1 plus the number of Unicode code points in `STRING`.
23
24 Example|Result
25 :--|:--
26 `{{ "aaabaab" \| strings.Count "a" }}`|5
27 `{{ "aaabaab" \| strings.Count "aa" }}`|2
28 `{{ "aaabaab" \| strings.Count "aaa" }}`|1
29 `{{ "aaabaab" \| strings.Count "" }}`|8