Is there an equivalent of str_replace in C++?
In PHP, there is a str_replace function 开发者_如何转开发that basically does a find and replace. Is there an equivalent of this function in C++?
Not exactly, but take a look at the Boost String Algorithms Library - in this case the replace functions:
std::string str("aabbaadd");
boost::algorithm::replace_all(str, "aa", "xx");
str now contains "xxbbxxdd".
std::string::replace will do replacement. You can couple it with std::string::find* methods to get similar functionality. It's not as easy as the PHP way. I think Boost has what you're looking for though; in regular expressions.
You can also use std::regex_replace
加载中,请稍侯......
精彩评论