I was wondering if there was any possible way to create a string function like string.length() or string.find(). This what I have so far, but I'd like to have it be string.rplce(find,replace) instead of string = rplce(string,find,replace).
That outputs "That at an example string" whichs is what I want it to do. But I want to do this instead:Code:#include <string.h> #include <iostream> using namespace std; string rplce(string, string, string); string rplce(string str, string find, string replace) { int pos = str.find(find); while(pos!=string::npos) { str.replace(pos, find.size(), replace); pos = str.find(find, pos); } return str; } int main() { string exmpl = "This is an example string"; exmpl = rplce(exmpl, "is", "at"); cout << exmpl << endl; system("PAUSE"); return 0; }
Any help is greatly appreciated. Thanks!!!Code:... exmpl.rplce("is","at"); ...



LinkBack URL
About LinkBacks


