/* Strip a set of characters from a string Picat. From Rosetta code: http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string """ The task is to create a function that strips a set of characters from a string. The function should take two arguments: the first argument being a string to stripped and the second, a string containing the set of characters to be stripped. The returned string should contain the first string, stripped of any characters in the second argument: print stripchars("She was a soul stripper. She took my heart!","aei") Sh ws soul strppr. Sh took my hrt! """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. 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).