Re: Removing a character from a string



Thansk! That's where they hid it!

- A
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:OvQJq2KmHHA.4688@xxxxxxxxxxxxxxxxxxxxxxx
Andrew Chalk <achalk@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Am I missing something? std::string() doesn't seem to have a member to
remove all occurances of a character from a string.

For example, given:

s = "encyclopedia"

s.remove('e')

yields:

"ncyclopdia"

What is the best way to do this?

#include <algorithm>

s.erase(std::remove(s.begin(), s.end(), 'e'), s.end());

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925




.



Relevant Pages


Loading