Logo

Programming-Idioms

History of Idiom 63 > diff from v49 to v50

Edit summary for version 50 by programming-idioms.org:
[Rust] +DocURL

Version 49

2021-03-25, 17:50:06

Version 50

2021-03-25, 17:52:34

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
Code
let x2 = x.replace(&y, &z);
Code
let x2 = x.replace(&y, &z);
Comments bubble
Returns a string slice (&str). Add .to_string() or .to_owned() to get a String.
Comments bubble
Returns a string slice (&str). Add .to_string() or .to_owned() to get a String.
Doc URL
https://doc.rust-lang.org/std/primitive.str.html#method.replace
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=568c9ebbfe29dfa173d6de1bf19f0e51
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=568c9ebbfe29dfa173d6de1bf19f0e51