Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A helper function to replace "all" occurances of "src" with "dest" in a C++ string. (collected)
- string replaceAll(string str, const string& src, const string& dest) {
- auto start_pos = 0;
- while((start_pos = str.find(src, start_pos)) != string::npos) {
- str.replace(start_pos, src.length(), dest);
- start_pos += dest.length(); // Handles case where 'dest' is a substring of 'src'
- }
- return str;
- }
- // Sample Problem: LeetCode 1108
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement