| 1 |
--- |
| 2 |
title: strings.Replace |
| 3 |
description: Returns the given string, replacing all occurrences of OLD with NEW. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [replace] |
| 9 |
returnType: string |
| 10 |
signatures: ['strings.Replace STRING OLD NEW [LIMIT]'] |
| 11 |
aliases: [/functions/replace] |
| 12 |
--- |
| 13 |
|
| 14 |
```go-html-template |
| 15 |
{{ $s := "Batman and Robin" }} |
| 16 |
{{ replace $s "Robin" "Catwoman" }} → Batman and Catwoman |
| 17 |
``` |
| 18 |
|
| 19 |
Limit the number of replacements using the `LIMIT` argument: |
| 20 |
|
| 21 |
```go-html-template |
| 22 |
{{ replace "aabbaabb" "a" "z" 2 }} → zzbbaabb |
| 23 |
``` |