Skip to content

Instantly share code, notes, and snippets.

@rozzy
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save rozzy/d3383dc4e2023de5e818 to your computer and use it in GitHub Desktop.

Select an option

Save rozzy/d3383dc4e2023de5e818 to your computer and use it in GitHub Desktop.

Revisions

  1. rozzy revised this gist Mar 4, 2015. 2 changed files with 8 additions and 16 deletions.
    8 changes: 8 additions & 0 deletions replace_string_in_place.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    void replace_string_in_place(std::string& subject, const std::string& search,
    const std::string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != std::string::npos) {
    subject.replace(pos, search.length(), replace);
    pos += replace.length();
    }
    }
    16 changes: 0 additions & 16 deletions vova2.cpp
    Original file line number Diff line number Diff line change
    @@ -1,16 +0,0 @@
    void ReplaceStringInPlace(std::string& subject, const std::string& search,
    const std::string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != std::string::npos) {
    subject.replace(pos, search.length(), replace);
    pos += replace.length();
    }
    }

    void main () {
    std::string input = "JIeIIIa г0нд0н ";
    input = ReplaceString(input, "JI", "л");
    input = ReplaceString(input, "III", "ш");
    # и так все совпадения
    std::cout << input
    }
  2. rozzy created this gist Jan 14, 2015.
    16 changes: 16 additions & 0 deletions vova2.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    void ReplaceStringInPlace(std::string& subject, const std::string& search,
    const std::string& replace) {
    size_t pos = 0;
    while ((pos = subject.find(search, pos)) != std::string::npos) {
    subject.replace(pos, search.length(), replace);
    pos += replace.length();
    }
    }

    void main () {
    std::string input = "JIeIIIa г0нд0н ";
    input = ReplaceString(input, "JI", "л");
    input = ReplaceString(input, "III", "ш");
    # и так все совпадения
    std::cout << input
    }