I am using the following code for replacing special characters in a system date format in Windows OS.
But I can only replace one character.
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str("10/16/13");
string str2("/");
str.replace(str.find(str2),str2.length(),"-");
cout << str << endl;
return 0;
}
Output:
10-16/13
If you only want to replace single characters then you can use std::replace from the <algorithm> header:
std::replace(str.begin(), str.end(), '/', '-');
This will replace all '/' in your string by '-'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With