Bukz

Untitled

May 19th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. void replacestr(char *arg1, char *arg2, char *arg3)
  2. {
  3.     string output;
  4.     char *ptr = strstr(arg1, arg2);
  5.  
  6.     if(!ptr) { result(arg1); return; } // Return the string untouched if arg2 cannot be found in arg1
  7.  
  8.     strncpy(output, arg1, ptr - arg1); // Copy every char in the original string, before the ptr, to string "output"
  9.     output[ptr - arg1] = 0;
  10.     sprintf(output + (ptr - arg1), "%s%s", arg3, ptr + strlen(arg2)); // Concatenate the new string to the output
  11.     result(output);                                                   // then the remainder of the original string
  12. }
  13. COMMAND(replacestr, ARG_3STR);
Advertisement
Add Comment
Please, Sign In to add comment