Logo

Programming-Idioms

History of Idiom 63 > diff from v60 to v61

Edit summary for version 61 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 60

2024-05-12, 12:00:10

Version 61

2024-08-29, 11:45:23

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Variables
x2,x,y,z
Variables
x2,x,y,z
Extra Keywords
substring substitute
Extra Keywords
substring substitute
Imports
import "strings"
Code
x2 := strings.ReplaceAll(x, y, z)
Comments bubble
This replaces non-overlapping instances of y.
Doc URL
https://pkg.go.dev/strings#ReplaceAll
Demo URL
https://go.dev/play/p/OiwZvH8IBZL