summaryrefslogtreecommitdiff
path: root/9p44.cpp
blob: 263d12248e992fdf09fd4b75636db55587b7748e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>

/*
 *
 * 9.44
 *
 *
 */

std::string &replace_substr(std::string &s,
							const std::string oldval,
							const std::string newval) {
	
	for(decltype(s.size()) i = 0 ; i < s.size() ; ) {
		if(s.substr(i, oldval.size()) == oldval) {
			s.replace(i, oldval.size(), newval);
			i += newval.size();
		} else {
			++i;
		}
	}
	
	return s;
}

int main () {

	std::string a = "hahahaha WOW a WO hah WOW WOW WOW";
	std::string b = "tho though to tho yo tho bro tho";
	std::cout << replace_substr(a, "WOW", "wow!") << std::endl;
	std::cout << replace_substr(b, "tho", "though") << std::endl;
	return 0;
}