View source code
Display the source code in std/string.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.string.lastIndexOf - multiple declarations

Function lastIndexOf

ptrdiff_t lastIndexOf(Char) (
  const(Char)[] s,
  in dchar c,
  in CaseSensitive cs = Yes.caseSensitive
) pure @safe
if (isSomeChar!Char);

ptrdiff_t lastIndexOf(Char) (
  const(Char)[] s,
  in dchar c,
  in size_t startIdx,
  in CaseSensitive cs = Yes.caseSensitive
) pure @safe
if (isSomeChar!Char);

Parameters

NameDescription
s string to search
c character to search for
startIdx the index into s to start searching from
cs Yes.caseSensitive or No.caseSensitive

Returns

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 UTFException may be thrown.

cs indicates whether the comparisons are case sensitive.

Example

import std.typecons : No;

string s = "Hello World";
writeln(lastIndexOf(s, 'l')); // 9
writeln(lastIndexOf(s, 'Z')); // -1
writeln(lastIndexOf(s, 'L', No.caseSensitive)); // 9

Example

import std.typecons : No;

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

Function lastIndexOf

ptrdiff_t lastIndexOf(Char1, Char2) (
  const(Char1)[] s,
  const(Char2)[] sub,
  in CaseSensitive cs = Yes.caseSensitive
) pure @safe
if (isSomeChar!Char1 && isSomeChar!Char2);

ptrdiff_t lastIndexOf(Char1, Char2) (
  const(Char1)[] s,
  const(Char2)[] sub,
  in size_t startIdx,
  in CaseSensitive cs = Yes.caseSensitive
) pure @safe
if (isSomeChar!Char1 && isSomeChar!Char2);

Parameters

NameDescription
s string to search
sub substring to search for
startIdx the index into s to start searching from
cs Yes.caseSensitive or No.caseSensitive

Returns

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 UTFException may be thrown.

cs indicates whether the comparisons are case sensitive.

Example

import std.typecons : No;

string s = "Hello World";
writeln(lastIndexOf(s, "ll")); // 2
writeln(lastIndexOf(s, "Zo")); // -1
writeln(lastIndexOf(s, "lL", No.caseSensitive)); // 2

Example

import std.typecons : No;

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

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis

License

Boost License 1.0.