View source code
Display the source code in std/string.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla 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 usinglocal clone.

Function std.string.indexOfAny

Searches the string haystack for one of the characters in needles starting at index startIdx. If startIdx is not given, it defaults to 0.

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

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

Parameters

NameDescription
haystack string to search for needles in
needles characters to search for in haystack
startIdx index of a well-formed code point in haystack to start searching from; defaults to 0
cs specifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive)

Returns

The index of the first occurrence of any of the elements of needles in haystack. If no element of needles is found or startIdx is greater than or equal to haystack.length, then -1 is returned. If the parameters are not valid UTF, the result will still be either -1 or in the range [startIdx .. haystack.length], but will not be reliable otherwise.

Throws

If the sequence starting at startIdx does not represent a well-formed code point, then a UTFException may be thrown.

Example

import std.conv : to;

ptrdiff_t i = "helloWorld".indexOfAny("Wr");
writeln(i); // 5
i = "öällo world".indexOfAny("lo ");
writeln(i); // 4

Example

import std.conv : to;

ptrdiff_t i = "helloWorld".indexOfAny("Wr", 4);
writeln(i); // 5

i = "Foo öällo world".indexOfAny("lh", 3);
writeln(i); // 8

Authors

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

License

Boost License 1.0.