View source code
Display the source code in std/string.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.
std.string.index_of_any
- multiple declarations
- Function indexOfAny
- Function indexOfAny
Function indexOfAny
Returns the index of the first occurence of any of the elements in
in needles
. If no element of haystack
is found,
then needles
-1
is returned. The
slices startIdx
s
in the following
way
. haystack
[startIdx
.. $]
represents a codeunit
index in startIdx
. If the sequence ending at haystack
does not
represent a well formed codepoint, then a startIdx
std.utf.UTFException
may be
thrown.
Prototype
ptrdiff_t indexOfAny(Char, Char2)( const(Char)[] haystack, const(Char2)[] needles, size_t startIdx, CaseSensitive cs = CaseSensitive.yes ) 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 . 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", 4); assert(i == 5); i = "Foo öällo world".indexOfAny("lh", 3); assert(i == 8, to!string(i));
Function indexOfAny
Returns the index of the first occurence of any of the elements in
in needles
. If no element of haystack
is found,
then needles
-1
is returned.
Prototype
ptrdiff_t indexOfAny(Char, Char2)( const(Char)[] haystack, const(Char2)[] needles, CaseSensitive cs = CaseSensitive.yes ) pure @safe if (isSomeChar!Char && isSomeChar!Char2);
Parameters
Name | Description |
---|---|
haystack | String to search for needles in. |
needles | Strings to search for in haystack . |
cs | Indicates whether the comparisons are case sensitive. |
Example
import std.conv : to; ptrdiff_t i = "helloWorld".indexOfAny("Wr"); assert(i == 5); i = "öällo world".indexOfAny("lo "); assert(i == 4, to!string(i));
Authors
Walter Bright, Andrei Alexandrescu, and Jonathan M Davis