find

Same as the overload for strings, but with only a char*, making it faster as it cannot do a boundary check.

Sometimes when looking for a character it is helpful to append it as a sentinel to the char buffer and then use this function instead of the slower one that checks the boundary constantly.

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

Examples

// Find a ']' in a buffer of 1024 bytes using an additional sentinel.
size_t length = 1024;
char[] buffer = new char[](length+1);
buffer[length] = ']';
auto pos = buffer.ptr.find!("=]");
if (pos < length) { // was an actual find before the sentinel }

Meta