remove character from string on condition c++ code example

Example: remove character from string on condition c++

class IsChars
{
public:
    IsChars(const char* charsToRemove) : chars(charsToRemove) {};

    bool operator()(char c)
    {
        for(const char* testChar = chars; *testChar != 0; ++testChar)
        {
            if(*testChar == c) { return true; }
        }
        return false;
    }

private:
    const char* chars;
};
auto chars_to_remove = "()- ";
str.erase(std::remove_if(str.begin(), str.end(), IsChars(chars_to_remove)), str.end());

Tags:

Misc Example