find

Finds the first occurrence of a set of compile-time known code units in a string. While the algorithm is O(n) in relation to the count of given code units, the overhead when using it on short strings weights more for only 1 or 2 code units.

  1. size_t find(char[] str)
    pure nothrow
    size_t
    find
    (
    string match
    )
    (
    in char[] str
    )
  2. inout(char)* find(inout(char*) ptr)

Parameters

match

An expression that matches all characters around which a split should occur.

str char[]

The string to search for a code unit.

Return Value

Type: size_t

If a match is found, the index into the string is returned. Otherwise an invalid index is returned. Check with if (result < str.length).

Examples

// Check if there is a '/' or '\' in the string
auto pos = str.find!(`or(=/,=\)`);
if (pos < str.length) { }

See Also

Meta