As I’m just a C++ poser, I don’t know a lot of things programming in this language especially if I have to deal with STL (Standard Template Library). As some of you know, when you’re not using third party libraries in C++, programming gets a little harder (note : my harder is harder than your harder).
So I searched the web and found this solution. Unfortunately, I forgot where I got this. Anyway, the original program doesn’t work.
#include
#include
using namespace std;
int main()
{
string str( "The Horse and the Yokaba" );
string searchString( "Yokaba" );
string replaceString( "Kabayo" );
string::size_type pos = 0;
while ( (pos = str.find(searchString, pos)) != string::npos ) {
str.replace( pos, searchString.size(), replaceString );
pos++;
}
cout << str << endl;
return 0;
}
When I'm using the MString library, it was a breeze. There's a ton of methods that makes things easy but when you need to make your program faster and leaner, you wouldn't want the extra baggage that comes with a third party library. MString is good but it's just brings with it too much things I don't need on my program.
If I have time(which most of the time I spend sleeping), I'll update the post to include a line by line explanation. It's not exactly for you but for me. It's a note to myself.
Ciao!
Incoming search terms:
- string replace in c
- string replace c
- StringReplace c
Recent Comments