token.erase(std::remove_if(token.begin(), token.end(), ispunct), token.end());
It seems that using ispunct will remove all punctuation. Is it possible to only remove certain types? For example if I want to remove all punctuation except, for example colon? Or do you have to write your own condition in that case?
Asked
Active
Viewed 621 times
0
user3221454
- 23
- 6
1 Answers
0
Use a lambda (or a callable object) as the predicate of your token.erase(...) call:
token.erase(
std::remove_if(
token.begin(),
token.end(),
[](char x){ return ispunct(x) && x != ':'; }),
token.end());
Vittorio Romeo
- 90,666
- 33
- 258
- 416
-
Thank you, this solved the problem in a very efficient way! – user3221454 Dec 11 '16 at 22:52