12345678910111213141516171819202122232425262728
#include <iostream> #include <string> using std::cout; using std::string; using std::endl; void parseLine(string &line) { constexpr char DELIMITER_ONE = '|'; constexpr char DELIMITER_TWO = '['; for (int i = 0; i < line.length(); i++) { if (line[i] == DELIMITER_ONE || line[i] == DELIMITER_TWO) { line.erase(i, 1); } } cout << line << endl; } int main() { std::string testString = "H|el[l|o|"; parseLine(testString); system("pause"); return 0; }
1234
//http://en.cppreference.com/w/cpp/algorithm/remove //https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom line.erase( std::remove_if(line.begin(), line.end(), [](char c) { return c == '|' || c == '['; }), line.end() );