开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜