1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| /**
* @brief replace all occurence of a string by another string, into a given string
*
* @param str string in wich something must be replaced
* @param sb string that must be replaced
* @param sa string that sb must be replaced by
* @return the string that result of this replacement
*/
std::string& replace(std::string& str, const std::string sb, const std::string sa)
{
std::string::size_type n, nb = 0;
while ((n = str.find(sb,nb)) != std::string::npos)
{
str.replace(n,sb.size(),sa);
nb = n + sa.size();
}
return str;
} |