Logo

Programming-Idioms

History of Idiom 63 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-04-14, 21:30:20

Version 2

2015-04-14, 21:31:29

Idiom #63 Replace fragment of a string

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

Idiom #63 Replace fragment of a string

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

Imports
import "strings"
Imports
import "strings"
Code
x2 := strings.Replace(x, y, z, -1)
Code
x2 := strings.Replace(x, y, z, -1)
Comments bubble
-1 means "no limit on the number of replacements".
Comments bubble
-1 means "no limit on the number of replacements".
This replaces non-overlapping instances of y.
Origin
http://golang.org/pkg/strings/#Replace
Origin
http://golang.org/pkg/strings/#Replace
Demo URL
https://play.golang.org/p/UV-04jpLY8
Demo URL
https://play.golang.org/p/UV-04jpLY8