Strip a set of characters from a string: Difference between revisions
Strip a set of characters from a string (view source)
Revision as of 03:03, 5 September 2022
, 1 year agoAdds slope example
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Adds slope example) |
||
Line 2,451:
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
=={{header|Slope}}==
This example ignores all type/error checking in favor of brevity and assumes
two strings will be given. A solution could also likely be crafted using '''regex-replace'''
or '''string-replace'''.
<syntaxhighlight lang="slope">(define strip-chars (lambda (str chrs)
(define chr-list (map (lambda (ch) (string->rune ch)) (string->list chrs)))
(list->string
(filter
(lambda (ch) (not (member? chr-list (string->rune ch))))
(string->list str)))))
(display (strip-chars "She was a soul stripper. She took my heart!" "aei"))</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
=={{header|Smalltalk}}==
|