Replace a character with another.(Comparison is case-sensitive.)
This overloaded member function replaces instances of the substring lpszOld with instances of the string lpszNew. Set comparison is case-sensitive or not by argument bCaseSensitive.
This overloaded member function replaces instances of the all characters as specified by lpszOneOf with the character chNew. If the resulted string has repeated occurance of chNew, they are stripped so that only one is left
int Replace( char chOld, char chNew )
int Replace( LPCSTR lpszOld, LPCSTR lpszNew, BOOL bCaseSensitive = TRUE )
int Replace( LPCSTR lpszOneOf, char chNew )
The number of replaced instances of the character. Zero if the string isn't changed.
The number of replaced instances of the character. Zero if the string isn't changed.
The number of replaced instances of the chNew. Zero if no replacement took place.
EX1
void string_Replace_ex1() { string str("A+B+C+"); int nRet = str.Replace('+','-'); out_int("", nRet);//3 out_str(str);//"A-B-C-" }
EX2
void string_Replace_ex2() { string str("Today is Friday"); char buffer[6] = "Friday"; int nRet = str.Replace(buffer,"Monday"); out_int("", nRet);//1 out_str(str);//"Today is Monday" }
EX3
void string_Replace_ex3() { string str("123 \t456, 789;\n\r1212"); int nRet = str.Replace(" \t\n\r,;",','); out_int("", nRet);//6 out_str(str);//"123,456,789,1212" }
origin.h