Skip to content
StrReplaceZstr

StrReplaceZstr

StrReplaceZstr

Description

Replace occurrences of a null-terminated string (Zstr) in string.

Parameters

Name Direction Description
s in,out Str to modify.
match in Null-terminated match string.
replacement in Null-terminated replacement string.
count in Maximum number of replacements. -1 means replace all occurences.

Success

Modifies s in place.

Failure

No replacement if match not found.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    void StrReplaceZstr(Str *s, const char *match, const char *replacement, size count) {
        ValidateStr(s);
        str_replace(s, match, ZstrLen(match), replacement, ZstrLen(replacement), count);
                StrMerge(&output_path, &file_path);
                LOG_INFO("{}", output_path);
                StrReplaceZstr(&output_path, "/", "-", -1);
                LOG_INFO("{}", output_path);
                    StrPushFrontCstr(&output_path, project.build_dir.data, project.build_dir.length);
                    LOG_INFO("{}", output_path);
                    StrReplaceZstr(&output_path, ".c", ".md", 1);
                    StrReplaceZstr(&output_path, ".h", ".md", 1);
                    LOG_INFO("{}\n\n", output_path);
                    LOG_INFO("{}", output_path);
                    StrReplaceZstr(&output_path, ".c", ".md", 1);
                    StrReplaceZstr(&output_path, ".h", ".md", 1);
                    LOG_INFO("{}\n\n", output_path);
        // Test StrReplaceZstr
        Str s1 = StrInitFromZstr("Hello World");
        StrReplaceZstr(&s1, "World", "Universe", 1);
        bool result = (ZstrCompare(s1.data, "Hello Universe") == 0);
        StrDeinit(&s1);
        s1 = StrInitFromZstr("Hello Hello Hello");
        StrReplaceZstr(&s1, "Hello", "Hi", 2);
        result = result && (ZstrCompare(s1.data, "Hi Hi Hello") == 0);
Last updated on