replace string
Definition
char *replace_string(char *string, char *search, char *replace, size_t offset);
Description
Replaces all instances in the source string
Parameters
- string
- Destination and the string which contents is replaced.
- search
- String which should be searched for.
- replace
- String which should be placed in to_string.
- offset
- Offset of where to start to search.
Return Value
On success, this functions returns string which may be located in a different memory address.
If the function fails, string is returned.
Example
#include <stdio.h> #include <libc/string.h> int main(int argc, char *argv[]) { char *original_string = create_string("Hello Something!"); original_string = replace_string(original_string, "Something", "World", 0); printf("Original string: %s\n", original_string); free(original_string); return 0; }
Output:
Orginal string: Hello World!