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

Line 1,854:
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Picat}}==
Two implementations:
* a function using list comprehension: stripchars/2
* a predicate using recursion: stripchars2/2
 
<lang Picat>go =>
S = "She was a soul stripper. She took my heart!",
println(stripchars(S, "aei")),
stripchars2(S, "aei", S2),
println(S2),
nl.
 
% List comprehension
stripchars(String, Chars) = [C : C in String, not(membchk(C,Chars))].
 
% Recursion
stripchars2(String,Chars, Res) =>
stripchars2(String, Chars, [], Res).
 
stripchars2([], _Chars, Res, Res).
stripchars2([H|T], Chars, Res1, Res) :-
membchk(H,Chars),
stripchars2(T, Chars, Res1, Res).
stripchars2([H|T], Chars, Res1, [H|Res]) :-
stripchars2(T, Chars, Res1, Res).</lang>
 
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!
Sh ws soul strppr. Sh took my hrt!</pre>
 
 
=={{header|PicoLisp}}==
495

edits