Suppose I want to remove everything after the last '*' (for example) in a string. Knowing that I can take the following for granted for that string:
What is the cleanest and/or shortest way to remove everything past the last '*', plus itself, with only basic libraries?
Given your assumptions:
s.erase(s.rfind('*'));
Without the assumption that it contains at least one *
:
auto pos = s.rfind('*');
if (pos != std::string::npos) {
s.erase(pos);
}
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