I have command string and want to find a pattern in it.If present i have to remove certain characters and retain the other characters as it is in the command string.
string aDir("bin/kwp-init start -t1 -uwelcome@mails.com -ppasstoks@123 -v");
string search_char ("@");
size_t found=0;
found = aDir.find_first_of(search_char);
cout <<"@ is found at:"<<found<<endl;
if (found!=string::npos){
cout<<"now :"<<aDir <<endl;
aDir.erase(found);
}
else {
aDir.clear(); /* str is all whitespace*/
}
cout<<"then:"<<aDir<<endl;
Actual output from code is : bin/kwp-init restart -t1 -uwelcome
Expected output is : bin/kwp-init restart -t1 -uwelcome -ppasstoks@123 -v
Suggest me a solution!!