StrFindStr

Table of Contents

StrFindStr

Description

Find a key in a Str object.

Parameters

NameDirectionDescription
strinStr object to find str into.
keyinStr object to find in str

Success

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

Failure

NULL

Usage example (Cross-references)

    // Test string find functions
    bool test_str_find(void) {
    printf("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);

Share :