StrReplace
- Function
- August 22, 2025
Table of Contents
StrReplace
StrReplace
Description
Replace occurrences of a Str in string with another Str.
Parameters
Name | Direction | Description |
---|---|---|
s | in,out | Str to modify. |
match | in | Str to match. |
replacement | in | Str to replace with. |
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)
- In
Str.c:259
:
}
void StrReplace(Str* s, const Str* match, const Str* replacement, size count) {
ValidateStr(s);
str_replace(s, match->data, match->length, replacement->data, replacement->length, count);
- In
Str.Ops.c:128
:
// Test string replace functions
bool test_str_replace(void) {
printf("Testing StrReplace variants\n");
// Test StrReplaceZstr
- In
Str.Ops.c:152
:
Str find = StrInitFromZstr("World");
Str replace = StrInitFromZstr("Universe");
StrReplace(&s1, &find, &replace, 1);
result = result && (ZstrCompare(s1.data, "Hello Universe") == 0);