Skip to content
StrIndexOfCstr

StrIndexOfCstr

StrIndexOfCstr

Description

Find the index of first occurrence of a fixed-length string.

Parameters

Name Direction Description
s in Str object to search in.
key in String to search for.
key_len in Length of searched string.

Success

Zero-based index of first match.

Failure

SIZE_MAX if no match is found.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    size StrIndexOfCstr(const Str *s, const char *key, size key_len) {
        return str_index_of_cstr(s, key, key_len);
    }
    
    bool StrContainsCstr(const Str *s, const char *key, size key_len) {
        return StrIndexOfCstr(s, key, key_len) != SIZE_MAX;
    }
        result      = result && (StrIndexOf(&haystack, &needle) == 6);
        result      = result && (StrIndexOfZstr(&haystack, "Hello") == 0);
        result      = result && (StrIndexOfCstr(&haystack, "World", 5) == 6);
        result      = result && !StrContainsZstr(&haystack, "missing");
        result      = result && (StrIndexOfZstr(&haystack, "missing") == SIZE_MAX);
Last updated on