StringSearch.locatePattern

Scans "str" for "pattern" and returns the index of the first occurrence if found.

struct StringSearch(bool wide_char = false)
static
size_t
locatePattern
(
in Char[] str
,,
size_t start = 0
)

Parameters

str Char[]

string to scan

pattern Char[]

search pattern

start size_t

start location to start searching

Return Value

Type: size_t

If found, the index of the first occurrence, or the length of "str" otherwise.

Examples

test!("==")(StringSearch!().locatePattern("Hello World!", "World", 0), 6);
test!("==")(StringSearch!().locatePattern("[Hello]", "[", 1), "[Hello]".length);
test!("==")(StringSearch!().locatePattern("[Hello]", "[", 256), "[Hello]".length);
// Crazy/inconsistent behavior: It should return 1
test!("==")(StringSearch!().locatePattern("[", "[", 1), 0);
test!("==")(StringSearch!().locatePattern("[", "[", 256), 0);

Meta