Skip to content

Commit f894859

Browse files
committed
Remove all occurences
1 parent 64a5f61 commit f894859

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Cpp programs/RemoveAllOccurences.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
string removeOccurrences(string s, string part)
7+
{
8+
while (s.length() > 0 && s.find(part) < s.length())
9+
{
10+
s.erase(s.find(part), part.length());
11+
}
12+
return s;
13+
}
14+
15+
int main()
16+
{
17+
18+
string str = "daabcbaabcbc";
19+
string part = "abc";
20+
21+
cout << removeOccurrences(str, part) << endl;
22+
23+
return 0;
24+
}

Cpp programs/RemoveAllOccurences.exe

47.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)