
Originally Posted by
tamimego
I'm really bad at the std shit,
so umm this might be newb but could someone write me a function that takes a string, finds a sub string and replaces only that substring with another string.
I would use string.replace but that doesnt "ONLY" replace that one thing im looking for, say I have "THIS IS A TEST"
I want it to look for "THIS" and replace with "LOLOLOL"
string.replace would do "LOLOLOL A TEST" I want "LOLOLOL IS A TEST"
Doing it the chopper way:
Code:
index = current.find(TEXT("__cdecl "));
if (index != string::npos) {
left = current.substr(0, index);
right = current.substr(index + 8,current.size() -index-8);
current = left.append(TEXT("CDECL ")).append(right);
}
where 8 is the length of TEXT("__cdecl ")

Originally Posted by
Trundle
O_o. You are joking?! Without std c++ would not be c++. Too bad so many people coding C here...
Anyway, this should work:
Code:
string s="THIS IS A TEST";
s.replace(s.find("THIS"), s.find("THIS")+4, "LOLOLOL");
This will replace only 4 characters, with "LOLO", he wants some kind of concatenation.
Bookmarks