replace

Replaces elements from array with indices ranging from from (inclusive) to to (exclusive) with the range stuff.

  1. E[] replace(E[] subject, R1 from, R2 to)
  2. E[] replace(E[] subject, R1 from, R2 to, size_t changed)
  3. T[] replace(T[] subject, size_t from, size_t to, Range stuff)
    T[]
    replace
    (
    T
    Range
    )
    (,
    size_t from
    ,
    size_t to
    ,
    Range stuff
    )
    if (
    isInputRange!Range &&
    (
    is(ElementType!Range : T) ||
    isSomeString!(T[]) &&
    is(ElementType!Range : dchar)
    )
    )

Parameters

subject T[]

the array to scan

from size_t

the starting index

to size_t

the ending index

stuff Range

the items to replace in-between from and to

Return Value

Type: T[]

A new array without changing the contents of subject.

Examples

auto a = [ 1, 2, 3, 4 ];
auto b = a.replace(1, 3, [ 9, 9, 9 ]);
assert(a == [ 1, 2, 3, 4 ]);
assert(b == [ 1, 9, 9, 9, 4 ]);

See Also

Meta