indexOf

Searches for character in range.

Parameters

s Range

string or InputRange of characters to search in correct UTF format

c dchar

character to search for

startIdx size_t

starting index to a well-formed code point

cs CaseSensitive

Yes.caseSensitive or No.caseSensitive

Return Value

Type: ptrdiff_t

the index of the first occurrence of c in s with respect to the start index startIdx. If c is not found, then -1 is returned. If c is found the value of the returned index is at least startIdx. If the parameters are not valid UTF, the result will still be in the range [-1 .. s.length], but will not be reliable otherwise.

Throws

If the sequence starting at startIdx does not represent a well formed codepoint, then a std.utf.UTFException may be thrown.

Examples

import std.typecons : No;

string s = "Hello World";
assert(indexOf(s, 'W') == 6);
assert(indexOf(s, 'Z') == -1);
assert(indexOf(s, 'w', No.caseSensitive) == 6);
import std.typecons : No;

string s = "Hello World";
assert(indexOf(s, 'W', 4) == 6);
assert(indexOf(s, 'Z', 100) == -1);
assert(indexOf(s, 'w', 3, No.caseSensitive) == 6);

See Also

Meta