The OpenD Programming Language

replaceInto

Replace occurrences of from with to in subject and output the result into sink. changed counts how many replacements took place.

  1. void replaceInto(Sink sink, E[] subject, R1 from, R2 to)
  2. void replaceInto(Sink sink, E[] subject, R1 from, R2 to, size_t changed)
    void
    replaceInto
    (
    E
    Sink
    R1
    R2
    )
    (
    Sink sink
    ,,
    R1 from
    ,
    R2 to
    ,
    ref size_t changed
    )
    if (
    isOutputRange!(Sink, E) &&
    (
    is(Unqual!E : Unqual!R1)
    )
    )

Parameters

sink Sink
subject E[]

the array to scan

from R1

the item to replace

to R2

the item to replace all instances of from with

changed size_t

the number of replacements

Examples

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

size_t changed = 0;
replaceInto(sink, arr, from, to, changed);

assert(sink.data == [1, 4, 6, 4, 5]);
assert(changed == 1);

Meta