Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Martin Brezl via Digitalmars-d-learn
Hi, i have a function like this: ``` import std.algorithm.iteration : substitute; //... string replace(string content, string[] searches , string replace) { if(searches.empty) return content; auto result = content.substitute(searches.front,replace); for(size_t

Re: Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Martin Brezl via Digitalmars-d-learn
On Saturday, 11 January 2020 at 17:10:02 UTC, Martin Brezl wrote: Hi, i have a function like this: ``` [...] auto result = content.substitute(searches.front,replace); for(size_t i=1; i < searches.length; i++) { searches.popFront(); result = result.substitu

Re: Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Jesse Phillips via Digitalmars-d-learn
On Saturday, 11 January 2020 at 17:10:02 UTC, Martin Brezl wrote: Hi, i have a function like this: ``` import std.algorithm.iteration : substitute; //... string replace(string content, string[] searches , string replace) { if(searches.empty) return content; auto resul

Re: Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Jesse Phillips via Digitalmars-d-learn
You can also turn your function into a fold. auto searches = ["1", "2"]; writeln (searches.fold!((a, b)  => a.substitute(b, "number").to!string)("come 1 come 2")) ;