lastIndexOf

  1. ptrdiff_t lastIndexOf(const(Char)[] s, dchar c, CaseSensitive cs)
  2. ptrdiff_t lastIndexOf(const(Char)[] s, dchar c, size_t startIdx, CaseSensitive cs)
  3. ptrdiff_t lastIndexOf(const(Char1)[] s, const(Char2)[] sub, CaseSensitive cs)
  4. ptrdiff_t lastIndexOf(const(Char1)[] s, const(Char2)[] sub, size_t startIdx, CaseSensitive cs)
    @safe pure
    ptrdiff_t
    lastIndexOf
    (
    Char1
    Char2
    )
    (
    const(Char1)[] s
    ,
    const(Char2)[] sub
    ,
    in size_t startIdx
    ,
    in CaseSensitive cs = Yes.caseSensitive
    )
    if (
    isSomeChar!Char1 &&
    )

Parameters

s const(Char1)[]

string to search

sub const(Char2)[]

substring to search for

startIdx size_t

the index into s to start searching from

cs CaseSensitive

Yes.caseSensitive or No.caseSensitive

Return Value

Type: ptrdiff_t

the index of the last occurrence of sub in s. If sub is not found, then -1 is returned. The startIdx slices s in the following way s[0 .. startIdx]. startIdx represents a codeunit index in s.

Throws

If the sequence ending at startIdx does not represent a well formed codepoint, then a std.utf.UTFException may be thrown.

cs indicates whether the comparisons are case sensitive.

Examples

import std.typecons : No;

string s = "Hello World";
assert(lastIndexOf(s, "ll") == 2);
assert(lastIndexOf(s, "Zo") == -1);
assert(lastIndexOf(s, "lL", No.caseSensitive) == 2);
import std.typecons : No;

string s = "Hello World";
assert(lastIndexOf(s, "ll", 4) == 2);
assert(lastIndexOf(s, "Zo", 128) == -1);
assert(lastIndexOf(s, "lL", 3, No.caseSensitive) == -1);

Meta