I have a std::string A I need to find in it string B with content like bla-bla-bla and replace it with other string C like abcdefg and if B was not found just put C at the beginning of A.
How to do such thing?
I have a std::string A I need to find in it string B with content like bla-bla-bla and replace it with other string C like abcdefg and if B was not found just put C at the beginning of A.
How to do such thing?
void replace_or_merge(std::string &a, const std::string &b, const std::string &c) { const std::string::size_type pos_b_in_a = a.find(b); if(pos_b_in_a == std::string::npos) { a.insert(0, c); } else { a.replace(pos_b_in_a, b.length(), c); } } const std::string&