Can anyone suggest a way of stripping tab characters ( "\t"s ) from a string? CString or std::string.
So that "1E10 " for example becomes "1E10".
The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
replace('\t', '') . The replace method will remove the tabs from the string by replacing them with empty strings.
hackingwords' answer gets you halfway there. But std::remove()
from <algorithm>
doesn't actually make the string any shorter -- it just returns an iterator saying "the new sequence would end here." You need to call my_string().erase()
to do that:
#include <string>
#include <algorithm> // For std::remove()
my_str.erase(std::remove(my_str.begin(), my_str.end(), '\t'), my_str.end());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With