Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'

This commit is contained in:
Bjørn Erik Pedersen
2023-12-04 15:24:01 +01:00
810 changed files with 24147 additions and 7766 deletions

View File

@@ -1,30 +1,26 @@
---
title: strings.Replace
linkTitle: replace
description: Replaces all occurrences of the search string with the replacement string.
categories: [functions]
description: Returns a copy of INPUT, replacing all occurrences of OLD with NEW.
categories: []
keywords: []
menu:
docs:
parent: functions
function:
action:
aliases: [replace]
related:
- functions/strings/FindRE
- functions/strings/FindRESubmatch
- functions/strings/ReplaceRE
returnType: string
signatures: ['strings.Replace INPUT OLD NEW [LIMIT]']
relatedFunctions:
- strings.FindRE
- strings.FindRESubmatch
- strings.Replace
- strings.ReplaceRE
aliases: [/functions/replace]
---
Replace returns a copy of `INPUT` with all occurrences of `OLD` replaced with `NEW`.
The number of replacements can be limited with an optional `LIMIT` argument.
```go-html-template
{{ $s := "Batman and Robin" }}
{{ replace $s "Robin" "Catwoman" }} → Batman and Catwoman
```
{{ replace "Batman and Robin" "Robin" "Catwoman" }}
→ "Batman and Catwoman"
{{ replace "aabbaabb" "a" "z" 2 }} → "zzbbaabb"
Limit the number of replacements using the `LIMIT` argument:
```go-html-template
{{ replace "aabbaabb" "a" "z" 2 }} → zzbbaabb
```