View source code
Display the source code in std/array.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.array.replaceLast
Replaces the last occurrence of
with from
in to
a
. Returns a
new array
without changing the contents of
, or the original
subject
array
if no match is found.
Prototype
E[] replaceLast(E, R1, R2)( E[] subject, R1 from, R2 to ) if (isDynamicArray!(E[]) && isForwardRange!R1 && is(typeof(appender!(E[])().put(from[0..1]))) && isForwardRange!R2 && is(typeof(appender!(E[])().put(to[0..1]))));
Example
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);
Authors
Andrei Alexandrescu and Jonathan M Davis