Logo

Programming-Idioms

History of Idiom 63 > diff from v7 to v8

Edit summary for version 8 by :

Version 7

2015-08-21, 01:03:46

Version 8

2015-08-21, 23:30:21

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".
This replaces non-overlapping instances of y.
Comments bubble
-1 means "no limit on the number of replacements".
This replaces non-overlapping instances of y.
Doc URL
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