c++ - Replace\remove character in string -
string delstr = "i! am! bored!"; string repstr = "10/07/10"
i want delete '!' on delstr , want replace '/' '-' on repstr string.
is there way without doing loop go through each character?
remove exclamations:
#include <algorithm> #include <iterator> std::string result; std::remove_copy(delstr.begin(), delstr.end(), std::back_inserter(result), '!');
alternatively, if want print string, don't need result
variable:
#include <iostream> std::remove_copy(delstr.begin(), delstr.end(), std::ostream_iterator<char>(std::cout), '!');
replace slashes dashes:
std::replace(repstr.begin(), repstr.end(), '/', '-');
Comments
Post a Comment