View source code
Display the source code in std/string.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.string.indexOfAny
Returns the index of the first occurrence of any of the elements in needles in haystack. If no element of needles is found,
then -1 is returned. The startIdx slices haystack in the
following way haystack[startIdx .. $]. startIdx represents a
codeunit index in haystack. If the sequence ending at startIdx
does not represent a well formed codepoint, then a UTFException
may be thrown.
ptrdiff_t indexOfAny(Char, Char2)
(
const(Char)[] haystack,
const(Char2)[] needles,
in CaseSensitive cs = Yes .caseSensitive
) pure @safe
if (isSomeChar!Char && isSomeChar!Char2);
ptrdiff_t indexOfAny(Char, Char2)
(
const(Char)[] haystack,
const(Char2)[] needles,
in size_t startIdx,
in CaseSensitive cs = Yes .caseSensitive
) pure @safe
if (isSomeChar!Char && isSomeChar!Char2);
Parameters
| Name | Description |
|---|---|
| haystack | String to search for needles in. |
| needles | Strings to search for in haystack. |
| startIdx | slices haystack like this haystack[startIdx .. $]. If
the startIdx is greater equal the length of haystack the functions
returns -1. |
| cs | Indicates whether the comparisons are case sensitive. |
Example
import std .conv : to;
ptrdiff_t i = "helloWorld" .indexOfAny("Wr");
writeln(i); // 5
i = "öällo world" .indexOfAny("lo ");
writeln(i); // 4
Example
import std .conv : to;
ptrdiff_t i = "helloWorld" .indexOfAny("Wr", 4);
writeln(i); // 5
i = "Foo öällo world" .indexOfAny("lh", 3);
writeln(i); // 8
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.