View source code
Display the source code in std/array.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.array.replaceInto

Replace occurrences of from with to in subject and output the result into sink.

void replaceInto(E, Sink, R1, R2) (
  Sink sink,
  E[] subject,
  R1 from,
  R2 to
)
if (isOutputRange!(Sink, E) && isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2));

Parameters

NameDescription
sink an output range
subject the array to scan
from the item to replace
to the item to replace all instances of from with

See Also

substitute for a lazy replace.

Example

auto arr = [1, 2, 3, 4, 5];
auto from = [2, 3];
auto to = [4, 6];
auto sink = appender!(int[])();

replaceInto(sink, arr, from, to);

writeln(sink.data); // [1, 4, 6, 4, 5]

Authors

Andrei Alexandrescu and Jonathan M Davis

License

Boost License 1.0.