In PHP, there is a str_replace
function that basically does a find and replace. Is there an equivalent of this function in C++?
views:
205answers:
2
+3
A:
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.
Duracell
2010-06-21 00:34:30
+5
A:
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"
.
Georg Fritzsche
2010-06-21 00:49:00
no unicode? what?
Kugel
2010-06-21 01:03:49
@Kugel: What are you aiming at? The string algorithms are abstract and work with any string fulfilling the [requirements](http://www.boost.org/doc/libs/1_43_0/doc/html/string_algo/design.html#string_algo.string). So go with `wstring`, use Boost.Locale with ICU or whatever fits best.
Georg Fritzsche
2010-06-21 01:53:00
@Kugel: what do you mean?
Joe
2010-06-21 01:54:14
Sorry I'm just upset with c++ lack of unicode support.
Kugel
2010-06-22 15:17:14