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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With