lastIndexOfNeither

Searches for the last character in haystack that is not in needles.

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

Parameters

haystack const(Char)[]

string to search for needles in

needles const(Char2)[]

characters to search for in haystack

stopIdx size_t

index in haystack to stop searching at (exclusive); defaults to haystack.length

cs CaseSensitive

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

Return Value

Type: ptrdiff_t

The index of the last character in haystack that is not an element of needles. If all characters of haystack are in needles 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

assert(lastIndexOfNeither("abba", "a") == 2);
assert(lastIndexOfNeither("def", "f") == 1);
assert(lastIndexOfNeither("def", "rsa", 3) == -1);
assert(lastIndexOfNeither("abba", "a", 2) == 1);

Meta