In PHP, there is a str_replace function that basically does a find and replace. Is there an equivalent of this function in C++?
- cplusplus.com/reference/string/string/replace will perform a string replace but won't do a search and replace.Anthony– Anthony2010-06-21 00:29:45 +00:00Commented Jun 21, 2010 at 0:29
Add a comment |
3 Answers
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".
2 Comments
Georg Fritzsche
@Kugel: What are you aiming at? The string algorithms are abstract and work with any string fulfilling the requirements. So go with
wstring, use Boost.Locale with ICU or whatever fits best.AbiusX
why would someone use boost for this basic functionality?
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.