Skip to content

Commit 7cfacb3

Browse files
string_replace_char.cpp
1 parent a06bc56 commit 7cfacb3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

string_replace_char.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
//https://stackoverflow.com/questions/2896600/how-to-replace-all-occurrences-of-a-character-in-string
8+
9+
int main()
10+
{
11+
string mystr = "2020/08/26";
12+
cout << mystr << " -> ";
13+
//the 3rd and 4th argument can only be a char, not a string
14+
replace(mystr.begin(), mystr.end(), '/', '-');
15+
cout << mystr << endl;
16+
17+
return 0;
18+
}
19+
20+
//2020/08/26 -> 2020-08-26

0 commit comments

Comments
 (0)