C Collections

cstring · Section 3

cstring_find

cstring_find - find the first occurrence of a substring

C Collections (libccollections, -lccollections)

#include <ccollections/cstring.h>
 
size_t cstring_find(cstr s, const char *needle);

This function looks for the first occurrence of needle in the string and
returns the zero-based index where it starts.

s        String to search
needle   Substring to find

Zero-based index of the first occurrence
0 if needle is an empty string (matches at the start)
ccol_invalid_size ((size_t)-1) if needle is not found, or if needle is NULL

Asserts if s is NULL

cstring_rfind(3), cstring_starts_with(3), cstring_ends_with(3)