Strip a set of characters from a string: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Added Perl 6 solution)
(→‎{{header|C++}}: Added C++ solution)
Line 4: Line 4:
<lang pseudocode> print stripchars("She was a soul stripper. She took my heart!","aei")
<lang pseudocode> print stripchars("She was a soul stripper. She took my heart!","aei")
Sh ws soul strppr. Sh took my hrt!</lang>
Sh ws soul strppr. Sh took my hrt!</lang>

=={{header|C++}}==
Note: this uses a C++0x lambda function
<lang cpp>#include <algorithm>
#include <iostream>
#include <string>

std::string stripchars(std::string str, const std::string &chars)
{
str.erase(
std::remove_if(str.begin(), str.end(), [&](char c){
return chars.find(c) != std::string::npos;
}),
str.end()
);
return str;
}

int main()
{
std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
}</lang>
Output:
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>


=={{header|D}}==
=={{header|D}}==