lastIndexOf

Parameters

s const(Char)[]

string to search

c dchar

character to search for

cs CaseSensitive

Yes.caseSensitive or No.caseSensitive

Return Value

Type: ptrdiff_t

The index of the last occurrence of c in s. If c 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, 'l') == 9);
assert(lastIndexOf(s, 'Z') == -1);
assert(lastIndexOf(s, 'L', No.caseSensitive) == 9);
import std.typecons : No;

string s = "Hello World";
assert(lastIndexOf(s, 'l', 4) == 3);
assert(lastIndexOf(s, 'Z', 1337) == -1);
assert(lastIndexOf(s, 'L', 7, No.caseSensitive) == 3);

Meta