replace

fnE[] replace(E, R1, R2)(E[] subject, R1 from, R2 to) if ((isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2)) || is(Unqual!E : Unqual!R1))

Replace occurrences of from with to in subject in a new array.

Parameters

subjectthe array to scan
fromthe item to replace
tothe item to replace all instances of from with

Returns

A new array without changing the contents of subject, or the original

array if no match is found.

See Also

substitute for a lazy replace.
fnE[] replace(E, R1, R2)(E[] subject, R1 from, R2 to, ref size_t changed) if ((isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2)) || is(Unqual!E : Unqual!R1))

Replace occurrences of from with to in subject in a new array. changed counts how many replacements took place.

Parameters

subjectthe array to scan
fromthe item to replace
tothe item to replace all instances of from with
changedthe number of replacements

Returns

A new array without changing the contents of subject, or the original

array if no match is found.

fnT[] replace(T, Range)(T[] subject, size_t from, size_t to, Range stuff) if (isInputRange!Range && (is(ElementType!Range : T) || isSomeString!(T[]) && is(ElementType!Range : dchar)))

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

Parameters

subjectthe array to scan
fromthe starting index
tothe ending index
stuffthe items to replace in-between from and to

Returns

A new array without changing the contents of subject.

See Also

substitute for a lazy replace.