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.

Function std.string.lastIndexOfAny

Returns the index of the last occurrence of any of the elements in needles in haystack. If no element of needles is found, then -1 is returned. The stopIdx slices haystack in the following way s[0 .. stopIdx]. stopIdx represents a codeunit index in haystack. If the sequence ending at startIdx does not represent a well formed codepoint, then a UTFException may be thrown.

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

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

Parameters

NameDescription
haystack String to search for needles in.
needles Strings to search for in haystack.
stopIdx slices haystack like this haystack[0 .. stopIdx]. If the stopIdx is greater than or equal to the length of haystack the functions returns -1.
cs Indicates whether the comparisons are case sensitive.

Example

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

i = "Foo öäöllo world".lastIndexOfAny("öF");
writeln(i); // 8

Example

import std.conv : to;

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

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

Authors

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

License

Boost License 1.0.