Logo

Programming-Idioms

History of Idiom 63 > diff from v36 to v37

Edit summary for version 37 by example12345:
New Cpp implementation by user [example12345]

Version 36

2019-09-27, 05:56:38

Version 37

2019-09-28, 16:15:52

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Extra Keywords
substring substitute
Extra Keywords
substring substitute
Imports
#include <string>
#include <iterator>
#include <regex>
#include <iostream>
Code
std::stringstream s;
std::regex_replace(std::ostreambuf_iterator<char>(s), x.begin(), x.end(), y, z);
auto x2 = s.str()
Doc URL
https://en.cppreference.com/w/cpp/regex/regex_replace
Origin
https://en.cppreference.com/w/cpp/regex/regex_replace