The OpenD Programming Language

indexOf

Searches for substring in s.

Parameters

s const(Char1)[]

string or ForwardRange of characters to search in correct UTF format

sub const(Char2)[]

substring to search for

startIdx size_t

the index into s to start searching from

Return Value

Type: ptrdiff_t

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

Throws

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

Bugs

Does not work with case insensitive strings where the mapping of tolower and toupper is not 1:1.

Examples

import std.typecons : No;

string s = "Hello World";
assert(indexOf(s, "Wo", 4) == 6);
assert(indexOf(s, "Zo", 100) == -1);
assert(indexOf(s, "wo", 3, No.caseSensitive) == 6);
import std.typecons : No;

string s = "Hello World";
assert(indexOf(s, "Wo") == 6);
assert(indexOf(s, "Zo") == -1);
assert(indexOf(s, "wO", No.caseSensitive) == 6);

Meta