indexOf

fnptrdiff_t indexOf(Range)(Range s, dchar c, CaseSensitive cs = Yes.caseSensitive) if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range)

Searches for a character in a string or range.

Parameters

sstring or InputRange of characters to search for c in
ccharacter to search for in s
startIdxindex to a well-formed code point in s to start searching from; defaults to 0
csspecifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive).

Returns

If c is found in s, then the index of its first occurrence is

returned. If c is not found or startIdx is greater than or equal to s.length, then -1 is returned. If the parameters are not valid UTF, the result will still be either -1 or in the range [startIdx .. s.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.

See Also

fnptrdiff_t indexOf(C)(scope const(C)[] s, dchar c, CaseSensitive cs = Yes.caseSensitive) if (isSomeChar!C)

Ditto

fnptrdiff_t indexOf(Range)(Range s, dchar c, size_t startIdx, CaseSensitive cs = Yes.caseSensitive) if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range)

Ditto

fnptrdiff_t indexOf(C)(scope const(C)[] s, dchar c, size_t startIdx, CaseSensitive cs = Yes.caseSensitive) if (isSomeChar!C)

Ditto

fnptrdiff_t indexOf(Range, Char)(Range s, const(Char)[] sub) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char)

Searches for a substring in a string or range.

Parameters

sstring or ForwardRange of characters to search for sub in
subsubstring to search for in s
startIdxindex to a well-formed code point in s to start searching from; defaults to 0
csspecifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive)

Returns

The index of the first occurrence of sub in s. If sub is not found

or startIdx is greater than or equal to s.length, then -1 is returned. If the arguments are not valid UTF, the result will still be either -1 or in the range [startIdx .. s.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.

Bugs

Does not work with case-insensitive strings where the mapping of toLower and toUpper is not 1:1.
fnptrdiff_t indexOf(Range, Char)(Range s, const(Char)[] sub, in CaseSensitive cs) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char)

Ditto

fnptrdiff_t indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx) if (isSomeChar!Char1 && isSomeChar!Char2) @safe

Ditto

fnptrdiff_t indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx, in CaseSensitive cs) if (isSomeChar!Char1 && isSomeChar!Char2) @safe

Ditto

fnptrdiff_t indexOf(Range, Char)(auto ref Range s, const(Char)[] sub) if (!(isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) && is(StringTypeOf!Range))
No documentation available for this declaration.
fnptrdiff_t indexOf(Range, Char)(auto ref Range s, const(Char)[] sub, in CaseSensitive cs) if (!(isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) && is(StringTypeOf!Range))
No documentation available for this declaration.