Strip a set of characters from a string: Difference between revisions
Content added Content deleted
(Oops, was wrong task) |
No edit summary |
||
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|Icon}} and {{header|Unicon}}== |
|||
The following works in both languages: |
|||
<lang unicon>procedure main(A) |
|||
cs := \A[1] | 'aei' # argument is set of characters to strip |
|||
every write(stripChars(!&input, cs)) # strip all input lines |
|||
end |
|||
procedure stripChars(s,cs) |
|||
ns := "" |
|||
s ? while ns ||:= 2(not pos(0), tab(upto(cs)|0), tab(many(cs)|0)) |
|||
return ns |
|||
end</lang> |
|||
Sample runs: |
|||
<pre>->strip |
|||
She was a soul stripper. She took my heart! |
|||
Sh ws soul strppr. Sh took my hrt! |
|||
Aardvarks are ant eaters. |
|||
Ardvrks r nt trs. |
|||
->strip AEIOUaeiou |
|||
Aardvarks are ant eaters. |
|||
rdvrks r nt trs. |
|||
-></pre> |
|||
=={{header|J}}== |
=={{header|J}}== |