View source code
Display the source code in std/array.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.array.replaceFirst
Replaces the first occurrence of from
with to
in subject
.
E[] replaceFirst(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]))));
Parameters
Name | Description |
---|---|
subject | the array to scan |
from | the item to replace |
to | the item to replace from with |
Returns
A new array without changing the contents of subject
, or the original
array if no match is found.
Example
auto a = [1, 2, 2, 3, 4, 5];
auto b = a .replaceFirst([2], [1337]);
writeln(b); // [1, 1337, 2, 3, 4, 5]
auto s = "This is a foo foo list";
auto r = s .replaceFirst("foo", "silly");
writeln(r); // "This is a silly foo list"
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.