Skip to content

StrFindStr

StrFindStr

Description

Find a key in a Str object.

Parameters

Name Direction Description
str in Str object to find str into.
key in Str object to find in str

Success

char* providing position of found string. Pointer is inside str

Failure

NULL

Usage example (Cross-references)

Usage examples (Cross-references)
                if (VecLen(str) > 0) {
                    Str   temp  = generate_str_from_input(data, offset, size, 10);
                    char *found = StrFindStr(str, &temp);
                    (void)found; // Suppress unused variable warning
                    StrDeinit(&temp);
    // Test string find functions
    bool test_str_find(void) {
        WriteFmt("Testing StrFindStr, StrFindZstr, and StrFindCstr\n");
    
        Str haystack = StrInitFromZstr("Hello World");
    
        // Test StrFindStr with match at end
        const char *found1 = StrFindStr(&haystack, &needle1);
        bool        result = (found1 != NULL && ZstrCompare(found1, "World") == 0);
    
        // Test StrFindStr with match at beginning
        const char *found2 = StrFindStr(&haystack, &needle2);
        result             = result && (found2 != NULL && ZstrCompare(found2, "Hello World") == 0);
    
        // Test StrFindStr with no match
        const char *found3 = StrFindStr(&haystack, &needle3);
        result             = result && (found3 == NULL);
Last updated on