View source code Display the source code in std/string.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

std.string.last_index_of_any - multiple declarations

Function lastIndexOfAny

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

Prototype

ptrdiff_t lastIndexOfAny(Char, Char2)(
  const(Char)[] haystack,
  const(Char2)[] needles,
  size_t stopIdx,
  CaseSensitive cs = CaseSensitive.yes
) 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 equal the length of haystack the functions returns -1.
cs Indicates whether the comparisons are case sensitive.

Example

import std.conv : to;

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

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

Function lastIndexOfAny

Returns the index of the last occurence of any of the elements in needles in haystack. If no element of needles is found, then -1 is returned.

Prototype

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

Parameters

NameDescription
haystack String to search for needles in.
needles Strings to search for in haystack.
cs Indicates whether the comparisons are case sensitive.

Example

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

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

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments