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.indexOfNeither

Searches haystack for a character not in needles.

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

ptrdiff_t indexOfNeither(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 character in haystack that is not an element of needles. If all characters of haystack are elements of needles 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

writeln(indexOfNeither("abba", "a", 2)); // 2
writeln(indexOfNeither("def", "de", 1)); // 2
writeln(indexOfNeither("dfefffg", "dfe", 4)); // 6

Example

writeln(indexOfNeither("def", "a")); // 0
writeln(indexOfNeither("def", "de")); // 2
writeln(indexOfNeither("dfefffg", "dfe")); // 6

Authors

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

License

Boost License 1.0.