Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void replacestr(char *arg1, char *arg2, char *arg3)
- {
- string output;
- char *ptr = strstr(arg1, arg2);
- if(!ptr) { result(arg1); return; } // Return the string untouched if arg2 cannot be found in arg1
- strncpy(output, arg1, ptr - arg1); // Copy every char in the original string, before the ptr, to string "output"
- output[ptr - arg1] = 0;
- sprintf(output + (ptr - arg1), "%s%s", arg3, ptr + strlen(arg2)); // Concatenate the new string to the output
- result(output); // then the remainder of the original string
- }
- COMMAND(replacestr, ARG_3STR);
Advertisement
Add Comment
Please, Sign In to add comment