lastIndexOfAny

Searches haystack for the last occurrence of any of the characters in needles.

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

Parameters

haystack const(Char)[]

string to search 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 last occurrence of any of the characters of needles in haystack. If no character of needles is found or stopIdx is 0, then -1 is returned. If the parameters are not valid UTF, the result will still be in the range [-1 .. stopIdx], but will not be reliable otherwise.

Examples

ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo");
assert(i == 8);

i = "Foo öäöllo world".lastIndexOfAny("öF");
assert(i == 8);
import std.conv : to;

ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo", 4);
assert(i == 3);

i = "Foo öäöllo world".lastIndexOfAny("öF", 3);
assert(i == 0);

Meta