I'm searching a text document and replacing substrings with other substrings. So for instance:
"ra,16(sp)" with "ra,16($sp)"
The issue I'm having is that say I have the following string:
"sp,sp,24"
How do I re-iteratively replace "sp" with "$sp" twice without getting:
"$$sp,$sp,24"
This is my code:
...
if ( words[i].find("sp")!=string::npos )
{
int temp = words[i].find("sp");
words[i].erase(temp,2);
words[i].insert(temp,"$sp");
cout << words[i] << endl;
}
...
I handle each string on a word by word basis by the way. I'm going to try to maybe same the location to memory and then cancel an if statement if that location is found again. Any ideas on a string function that will make this easier?