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 std.utf.UTFException may be thrown.

  1. ptrdiff_t indexOfAny(const(Char)[] haystack, const(Char2)[] needles, CaseSensitive cs)
    @safe pure
    ptrdiff_t
    indexOfAny
    (
    Char
    Char2
    )
    (
    const(Char)[] haystack
    ,
    const(Char2)[] needles
    ,
    in CaseSensitive cs = Yes.caseSensitive
    )
    if (
    isSomeChar!Char &&
    )
  2. ptrdiff_t indexOfAny(const(Char)[] haystack, const(Char2)[] needles, size_t startIdx, CaseSensitive cs)

Parameters

haystack const(Char)[]

String to search for needles in.

needles const(Char2)[]

Strings to search for in haystack.

cs CaseSensitive

Indicates whether the comparisons are case sensitive.

Examples

import std.conv : to;

ptrdiff_t i = "helloWorld".indexOfAny("Wr");
assert(i == 5);
i = "öällo world".indexOfAny("lo ");
assert(i == 4, to!string(i));
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));

Meta