Does anyone know where i can get a function that can take 3 strings and return a replaced version with all instances of the second string replaced by the third?
Lol, no its not homework, im trying to convert some code from a basic language to C++
The basic has a function called "Replace" which takes 3 strings and does as i described. I looked at the string::replace but none of its forms can take the 3 stings and do the job. If i use a position and size then surely if the replacer is longer than the replace-ee then thats going to overwrite more than i want it too :/ Plus im not sure how to even get the position or length i need either.
You will need to write your own replace function to duplicate the one you had.
If you look at the example in the reference Duoas gave you will see that str.replace(9,5,str2) will replace 5 characters starting at character 9 with the contents of str2 - extending str as required.
1 2 3 4
string base="this is a test string.";
string str2="n example";
string str=base; // "this is a test string."
str.replace(9,5,str2); // "this is an example string."
Try find and length from the strings library to complete the puzzle:-)
I'd advise quickly reading through the whole of the strings library reference (well, actualy the whole of the reference section) just to get an idea of what's there. Then the next time you have a problem you will have an idea what is directly possible, which is always a help.