mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
Reference in New Issue
Block a user