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.index_of_any - multiple declarations

Function indexOfAny

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

Prototype

ptrdiff_t indexOfAny(Char, Char2)(
  const(Char)[] haystack,
  const(Char2)[] needles,
  size_t startIdx,
  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.
startIdx slices haystack like this haystack[startIdx .. $]. If the startIdx 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".indexOfAny("Wr", 4);
assert(i == 5);

i = "Foo öällo world".indexOfAny("lh", 3);
assert(i == 8, to!string(i));

Function indexOfAny

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

Prototype

ptrdiff_t indexOfAny(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

import std.conv : to;

ptrdiff_t i = "helloWorld".indexOfAny("Wr");
assert(i == 5);
i = "öällo world".indexOfAny("lo ");
assert(i == 4, to!string(i));

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments