Skip to content
StrIndexOfZstr

StrIndexOfZstr

StrIndexOfZstr

Description

Find the index of first occurrence of a null-terminated string.

Parameters

Name Direction Description
s in Str object to search in.
key in Null-terminated string to search for.

Success

Zero-based index of first match.

Failure

SIZE_MAX if no match is found.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    size StrIndexOfZstr(const Str *s, const char *key) {
        if (!key) {
            LOG_FATAL("Invalid arguments");
    
    bool StrContainsZstr(const Str *s, const char *key) {
        return StrIndexOfZstr(s, key) != SIZE_MAX;
    }
        result      = result && StrContainsCstr(&haystack, "lo Wo", 5);
        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 && (StrIndexOfCstr(&haystack, "World", 5) == 6);
        result      = result && !StrContainsZstr(&haystack, "missing");
        result      = result && (StrIndexOfZstr(&haystack, "missing") == SIZE_MAX);
        result      = result && StrContainsZstr(&haystack, "");
        result      = result && (StrIndexOfZstr(&haystack, "") == 0);
        result      = result && (StrIndexOfZstr(&haystack, "missing") == SIZE_MAX);
        result      = result && StrContainsZstr(&haystack, "");
        result      = result && (StrIndexOfZstr(&haystack, "") == 0);
    
        StrDeinit(&haystack);
Last updated on