Function One:
1STD::stringCheckstring (std::string&strsource)2 {3STD::stringStroldvalue ="'";4STD::stringStrnewvalue =""'";5 for(std::string:: Size_type POS (0); POS! = std::string:: NPOs; pos + =strnewvalue.length ())6 { 7 if(pos = Strsource.find (Stroldvalue, pos))! = std::string:: NPOs)8 {9 Strsource.replace (POS, Stroldvalue.length (), strnewvalue); Ten } One Else A { - Break; - } the } - returnstrsource; -}
Method Two:
1STD::string& REPLACE_ALL_DISTINCT (std::string& STR,ConstSTD::string& Old_value,ConstSTD::string&new_value)2 {3 for(std::string:: Size_type POS (0); POS!=STD::string:: NPOs; pos+=new_value.length ())4 { 5 if((Pos=str.find (old_value,pos))! = std::string:: NPOs)6 str.replace (Pos,old_value.length (), new_value); 7 Else8 {9 Break;Ten } One } A returnstr; -}
Use:
For example:
Replace_all_distinct ("Sub ' ject","'","'" "); Checkstring ("subj ' e ' ct");
Single quotation mark in string
Escape function when SQL data is inserted into a string