Strip a set of characters from a string: Difference between revisions
Content added Content deleted
(added standard ml) |
(added haskell) |
||
Line 13: | Line 13: | ||
assert(s.removechars("aei") == ss); |
assert(s.removechars("aei") == ss); |
||
}</lang> |
}</lang> |
||
=={{header|Haskell}}== |
|||
I decided to make the string the second argument and the characters the first argument, because it is more likely for someone to partially apply the characters to be stripped (making a function that strips certain characters), than the string. |
|||
<lang haskell>stripChars :: String -> String -> String |
|||
stripChars = filter . flip notElem</lang> |
|||
testing in GHCI: |
|||
<pre>> stripChars "aei" "She was a soul stripper. She took my heart!" |
|||
"Sh ws soul strppr. Sh took my hrt!"</pre> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
The following works in both languages: |
The following works in both languages: |