Logo

Programming-Idioms

History of Idiom 63 > diff from v19 to v20

Edit summary for version 20 by :

Version 19

2015-10-31, 15:01:09

Version 20

2015-11-01, 23:12:45

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.

Imports
import std.stdio;
import std.array;
Imports
import std.array;
Code
void main()
{
	auto x = "111122223333";
	auto y = "22";
	auto z = "555";

	auto x2 = x.replace(y,z);  

        writeln(x2);

}
Code
auto x2 = x.replace(y,z);  
Comments bubble
same as
auto x2 = replace(x,y,z)
but easier to guess operation in this form
Comments bubble
Same as
auto x2 = replace(x,y,z)
but easier to guess operation in this form.
Doc URL
http://dlang.org/phobos/std_array.html#.replace
Doc URL
http://dlang.org/phobos/std_array.html#.replace