indexOfAny

Searches the string haystack for one of the characters in needles starting at index startIdx. If startIdx is not given, it defaults to 0.

  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)[]

characters to search for in haystack

cs CaseSensitive

specifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive)

Return Value

Type: ptrdiff_t

The index of the first occurrence of any of the elements of needles in haystack. If no element of needles is found or startIdx is greater than or equal to haystack.length, then -1 is returned. If the parameters are not valid UTF, the result will still be either -1 or in the range [startIdx .. haystack.length], but will not be reliable otherwise.

Throws

If the sequence starting at startIdx does not represent a well-formed code point, then a std.utf.UTFException may be thrown.

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