The OpenD Programming Language

replaceLast

Replaces the last occurrence of from with to in subject.

E[]
replaceLast
(
E
R1
R2
)
(,
R1 from
,
R2 to
)
if (
is(typeof(appender!(E[])().put(from[0 .. 1])))
&&
&&
is(typeof(appender!(E[])().put(to[0 .. 1])))
)

Parameters

subject E[]

the array to scan

from R1

the item to replace

to R2

the item to replace from with

Return Value

Type: E[]

A new array without changing the contents of subject, or the original array if no match is found.

Examples

auto a = [1, 2, 2, 3, 4, 5];
auto b = a.replaceLast([2], [1337]);
assert(b == [1, 2, 1337, 3, 4, 5]);

auto s = "This is a foo foo list";
auto r = s.replaceLast("foo", "silly");
assert(r == "This is a foo silly list", r);

Meta