Skip to content

Instantly share code, notes, and snippets.

@Meraj
Last active February 9, 2021 18:29

Revisions

  1. Meraj revised this gist Feb 9, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion replaceAll.cpp
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * @param from string
    * @param to string
    */
    string core::replaceAll(std::string str,std::string from, std::string to) {
    string replaceAll(std::string str,std::string from, std::string to) {
    if(from.empty())
    return str;
    size_t start_pos = 0;
  2. Meraj created this gist Feb 9, 2021.
    16 changes: 16 additions & 0 deletions replaceAll.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /**
    * replace text in string
    * @param str string
    * @param from string
    * @param to string
    */
    string core::replaceAll(std::string str,std::string from, std::string to) {
    if(from.empty())
    return str;
    size_t start_pos = 0;
    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
    str.replace(start_pos, from.length(), to);
    start_pos += to.length();
    }
    return str;
    }