Skip to content

StrIndexOf

StrIndexOf

Description

Find the index of first occurrence of another Str.

Parameters

Name Direction Description
s in Str object to search in.
key in Str object 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 StrIndexOf(const Str *s, const Str *key) {
        if (!key) {
            LOG_FATAL("Invalid arguments");
    // Test string contains/index functions
    bool test_str_contains_index(void) {
        WriteFmt("Testing StrContains and StrIndexOf variants\n");
    
        Str haystack = StrInitFromZstr("Hello World");
        result      = result && StrContainsZstr(&haystack, "Hello");
        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);
Last updated on