Strip a set of characters from a string: Difference between revisions
Content added Content deleted
(GP) |
|||
Line 103: | Line 103: | ||
<pre># stripchars "She was a soul stripper. She took my heart!" "aei" ;; |
<pre># stripchars "She was a soul stripper. She took my heart!" "aei" ;; |
||
- : string = "Sh ws soul strppr. Sh took my hrt!"</pre> |
- : string = "Sh ws soul strppr. Sh took my hrt!"</pre> |
||
=={{header|PARI/GP}}== |
|||
GP should not be used for string manipulation. A good solution to this problem would probably involve <code>system("perl -e</code>... |
|||
<lang parigp>stripchars(s, bad)={ |
|||
bad=Set(Vec(Vecsmall(bad))); |
|||
s=Vecsmall(s); |
|||
my(v=[]); |
|||
for(i=1,#s,if(!setsearch(bad,s[i]),v=concat(v,s[i]))); |
|||
Strchr(v) |
|||
}; |
|||
stripchars("She was a soul stripper. She took my heart!","aei")</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |