I wonder what escape characters you mean
if the escape characters are allways the same you can set the 3rd parameter of getline to be the first of the escape characters and then ignore the next x characters (where x is the amount of escape characters - 1)
getting rid of them is not the same as trimming...
to trim characters means to remove them from both ends of the string
To me that looks like a std::remove_if
you might want to have only numbers and letters in your string, you can use a lambda function in combination with std::erase and std::remove_if:
1 2 3 4
// remove if it is no space and no alphanumeric character
str.erase(std::remove_if(str.begin(), str.end(),
[](char c) { return !(std::isspace(c) || std::isalnum(c)); } ),
str.end());
if you know exactly what characters to ban you can make a string and bind that string to the lambda function: