erase any non numeric characters from an input
How do i erase a certain type of character from a string input?
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include <algorithm>
auto predicate_is_not_digit = [](const char& character) {
return !(::isdigit(character));
};
int main() {
std::string string = "a1b2c3d4,./-HELLOWORLD";
std::cout << "String before purging non-digit characters:\t" << string << std::endl;
string.erase(std::remove_if(string.begin(), string.end(), predicate_is_not_digit), string.end());
std::cout << "String after purging non-digit characters:\t" << string << std::endl;
return 0;
}
|
Topic archived. No new replies allowed.