hugo/content/en/functions/strings/Count.md
Bjørn Erik Pedersen 9b0050e9aa Squashed 'docs/' content from commit 5c085a37b
git-subtree-dir: docs
git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2024-01-27 10:48:33 +01:00

25 lines
737 B
Markdown

---
title: strings.Count
description: Returns the number of non-overlapping instances of the given substring within the given string.
categories: []
keywords: []
action:
aliases: []
related:
- functions/go-template/len
- functions/strings/CountRunes
- functions/strings/CountWords
- functions/strings/RuneCount
returnType: int
signatures: [strings.Count SUBSTR STRING]
aliases: [/functions/strings.count]
---
If `SUBSTR` is an empty string, this function returns 1 plus the number of Unicode code points in `STRING`.
```go-html-template
{{ "aaabaab" | strings.Count "a" }} → 5
{{ "aaabaab" | strings.Count "aa" }} → 2
{{ "aaabaab" | strings.Count "aaa" }} → 1
{{ "aaabaab" | strings.Count "" }} → 8
```