The OpenD Programming Language

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)
  2. ptrdiff_t indexOfAny(const(Char)[] haystack, const(Char2)[] needles, size_t startIdx, CaseSensitive cs)
    @safe pure
    ptrdiff_t
    indexOfAny
    (
    Char
    Char2
    )
    (
    const(Char)[] haystack
    ,
    const(Char2)[] needles
    ,
    in size_t startIdx
    ,
    in CaseSensitive cs = Yes.caseSensitive
    )
    if (
    isSomeChar!Char &&
    )

Parameters

haystack const(Char)[]

String to search for needles in.

needles const(Char2)[]

Strings to search for in haystack.

startIdx size_t

slices haystack like this haystack[startIdx .. $]. If the startIdx is greater than or equal to the length of haystack the functions returns -1.

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