replace_string()
#
replace_string()
replaces all occurrences of a substring within a given string with another substring, dynamically allocating memory for the new string.
Prototype
char *replace_string(
const char *str,
const char *old,
const char *snew
);
Parameters
Key |
Type |
Description |
---|---|---|
|
|
The input string in which replacements will be made. |
|
|
The substring to be replaced. |
|
|
The substring to replace occurrences of |
Return Value
A newly allocated string with all occurrences of old
replaced by snew
. Returns NULL
if memory allocation fails.
Notes
The caller is responsible for freeing the returned string using free()
. If old
is an empty string, the function will enter an infinite loop.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples