The OpenD Programming Language

replaceFirst

Replaces the first occurrence of from with to in subject.

E[]
replaceFirst
(
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.replaceFirst([2], [1337]);
assert(b == [1, 1337, 2, 3, 4, 5]);

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

Meta