replace

Performs a linear scan of complete array, replacing occurrences of specified element with the new element. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

  1. size_t replace(T[] array, T element, T new_element, Pred pred)
  2. size_t replace(Buffer!(T) array, T element, T new_element, Pred pred)
    size_t
    replace
    (
    ref Buffer!(T) array
    ,
    in T element
    ,,
    Pred pred = Pred.init
    )

Parameters

array Buffer!(T)

The array to scan.

element T

The pattern to match.

new_element T

The value to substitute.

pred Pred

The evaluation predicate, which should return true if e1 is equal to e2 and false if not. This predicate may be any callable type.

Return Value

Type: size_t

The number of elements replaced.

Examples

auto array = "abbbbc".dup;
test!("==")(replace(array, 'b', 'x'), 4);
test!("==")(array, "axxxxc");
auto buffer = createBuffer("abbbbc");
test!("==")(replace(buffer, 'b', 'x'), 4);
test!("==")(buffer[], "axxxxc");

Meta