strings.Replace
Returns the given string, replacing all occurrences of OLD with NEW.
- Syntax
- strings.Replace STRING OLD NEW [LIMIT]
- Returns
- string
- Alias
- replace
Usage
The strings.Replace function returns the given string, replacing all occurrences of OLD with NEW. To limit the number of replacements, pass the optional LIMIT argument.
Examples
{{ $s := "Batman and Robin" }}
{{ strings.Replace $s "Robin" "Catwoman" }} → Batman and CatwomanLimiting the number of replacements:
{{ strings.Replace "aabbaabb" "a" "z" 2 }} → zzbbaabbLast updated:
October 28, 2026
:
content: Apply style guide to strings functions (d6de31ebd)
Improve this page