How to find and replace all occurrences of a substring in a string?

前端 未结 7 1489
无人共我
无人共我 2020-12-31 06:49

I need to search a string and edit the formatting of it.

So far I can replace the first occurrence of the string, but I am unable to do so with the next occurrences

7条回答
  •  粉色の甜心
    2020-12-31 07:19

    Use std::regex_replace available with C++11. This does exactly what you want and more.

    https://en.cppreference.com/w/cpp/regex/regex_replace

    std::string const result = std::regex_replace( chartDataString, std::regex( "\\*A" ), "[A]\n" );
    

提交回复
热议问题