How to find and replace string?

后端 未结 10 1098
感动是毒
感动是毒 2020-11-27 03:51

If s is a std::string, then is there a function like the following?

s.replace(\"text to replace\", \"new text\");
10条回答
  •  离开以前
    2020-11-27 04:12

    Not exactly that, but std::string has many replace overloaded functions.

    Go through this link to see explanation of each, with examples as to how they're used.

    Also, there are several versions of string::find functions (listed below) which you can use in conjunction with string::replace.

    • find
    • rfind
    • find_first_of
    • find_last_of
    • find_first_not_of
    • find_last_not_of

    Also, note that there are several versions of replace functions available from which you can also use (instead of string::replace):

    • replace
    • replace_if
    • replace_copy
    • replace_copy_if

提交回复
热议问题