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

→‎{{header|Kotlin}}: Corrected Kotlin solution: the use of regex is error-prone, e.g. `stripChars("fails to remove ] bracket", "aei]")`
(→‎{{header|Picat}}: split into subsections)
(→‎{{header|Kotlin}}: Corrected Kotlin solution: the use of regex is error-prone, e.g. `stripChars("fails to remove ] bracket", "aei]")`)
 
(40 intermediate revisions by 22 users not shown)
Line 12:
<br>
The returned string should contain the first string, stripped of any characters in the second argument:
<langsyntaxhighlight lang="pseudocode"> print stripchars("She was a soul stripper. She took my heart!","aei")
Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
 
Line 22:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F stripchars(s, chars)
R s.filter(c -> c !C @chars).join(‘’)
 
print(stripchars(‘She was a soul stripper. She took my heart!’, ‘aei’))</langsyntaxhighlight>
 
{{out}}
Line 35:
{{trans|PL/I}}
The program uses two ASSIST macro (XDECO,XPRNT) to keep the code as short as possible.
<langsyntaxhighlight lang="360asm">* Strip a set of characters from a string 07/07/2016
STRIPCH CSECT
USING STRIPCH,R13 base register
Line 108:
* ---- -------------------------------------------------------
YREGS
END STRIPCH</langsyntaxhighlight>
{{out}}
<pre>
Line 116:
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm"> org 100h
jmp demo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 154:
jmp 5
string: db 'She was a soul stripper. She took my heart!$'
remove: db 'aei$'</langsyntaxhighlight>
 
{{out}}
Line 162:
=={{header|8086 Assembly}}==
 
<langsyntaxhighlight lang="asm"> bits 16
cpu 8086
section .text
Line 201:
section .data
string: db 'She was a soul stripper. She took my heart!$'
remove: db 'aei$'</langsyntaxhighlight>
 
{{out}}
 
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN s stripchars chs:
PUT "" IN result
FOR c IN s:
IF c not.in chs: PUT result^c IN result
RETURN result
 
WRITE "She was a soul stripper. She took my heart!" stripchars "aei"/</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Strip(CHAR ARRAY text,chars,res)
BYTE i,j,size,found
CHAR c
Line 242 ⟶ 253:
PrintE("Stripped string:")
PrintF("""%S""%E%E",result)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strip_a_set_of_characters_from_a_string.png Screenshot from Atari 8-bit computer]
Line 257 ⟶ 268:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
procedure Strip_Characters_From_String is
Line 283 ⟶ 294:
begin -- main
Ada.Text_IO.Put_Line(Strip(S, "aei"));
end Strip_Characters_From_String;</langsyntaxhighlight>
{{out}}
<pre>> ./strip_characters_from_string
Line 289 ⟶ 300:
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">text
stripchars1(data b, text w)
{
Line 319 ⟶ 330:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 325 ⟶ 336:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
PROC strip chars = (STRING mine, ore)STRING: (
Line 337 ⟶ 348:
);
 
printf(($gl$,stripchars("She was a soul stripper. She took my heart!","aei")))</langsyntaxhighlight>
{{out}}
<pre>
Line 344 ⟶ 355:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% returns s with the characters in remove removed %
% as all strings in Algol W are fixed length, the length of remove %
Line 384 ⟶ 395:
write( " ->: ", stripped( 0 // 64 ) )
end
end.</langsyntaxhighlight>
{{out}}
<pre>
text: She was a soul stripper. She took my heart!
->: Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Amazing Hopper}}==
<p>Amazing Hopper! Flavour "Jambo".</p>
<syntaxhighlight lang="Amazing Hopper">
#include <jambo.h>
 
Main
c = ".$%#\tEste@@@ mensaje será purgado!$$$"
 
{"Hopper assembler:\n\n"}
{"$%#@.\t", c} str to utf8, delete char, {"\n"} print
Printnl ("\nHopper Jambo formal syntax:\n\n", Char del ( "$%#@.\t", Utf8( c ) ) )
Set ' "\nHopper Jambo Natural syntax:\n\n", "$%#@.\t", c', Get utf8, and delete char
then print with newline
End
</syntaxhighlight>
{{out}}
<pre>
Hopper assembler:
 
Este mensaje será purgado!
 
Hopper Jambo formal syntax:
 
Este mensaje será purgado!
 
Hopper Jambo Natural syntax:
 
Este mensaje será purgado!
 
</pre>
 
Line 396 ⟶ 440:
a character vector, this can be used to remove characters from a string.
 
<langsyntaxhighlight APLlang="apl">'She was a soul stripper. She took my heart!' ~ 'aei'</langsyntaxhighlight>
 
{{out}}
Line 407 ⟶ 451:
 
{{works with|AppleScript|Mac OS X 10.6}}
<langsyntaxhighlight AppleScriptlang="applescript">stripChar("She was a soul stripper. She took my heart!", "aei")
 
on stripChar(str, chrs)
Line 419 ⟶ 463:
end tell
return str
end stripChar</langsyntaxhighlight>
{{out}}
<pre>
Line 430 ⟶ 474:
(Following the Haskell contribution in reversing the argument order to the sequence more probable in a context of potential currying or partial application).
 
<langsyntaxhighlight AppleScriptlang="applescript">-- stripChars :: String -> String -> String
on stripChars(needles, haystack)
script notNeedles
Line 486 ⟶ 530:
end script
end if
end mReturn</langsyntaxhighlight>
{{Out}}
<pre>"Sh ws soul strppr. Sh took my hrt!"</pre>
Line 493 ⟶ 537:
OS X Yosemite onwards – importing the Foundation classes to use NSRegularExpression
 
<langsyntaxhighlight AppleScriptlang="applescript">use framework "Foundation"
 
 
Line 600 ⟶ 644:
end script
end if
end mReturn</langsyntaxhighlight>
{{Out}}
<pre>"Sh ws soul strppr. Sh took my hrt!"</pre>
 
=={{header|Applesoft BASIC}}==
<langsyntaxhighlight lang="basic">100 LET S$ = "SHE WAS A SOUL STRIPPER. SHE TOOK MY HEART!"
110 LET RM$ = "AEI"
120 GOSUB 200STRIPCHARS
Line 625 ⟶ 669:
330 NEXT SI
340 RETURN
</syntaxhighlight>
</lang>
{{out}}
<pre>SH WS SOUL STRPPR. SH TOOK MY HRT!</pre>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">stripChars: function [str, chars]->
join select split str => [not? in? & split chars]
 
print stripChars "She was a soul stripper. She took my heart!" "aei"</langsyntaxhighlight>
 
{{out}}
 
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Asymptote}}==
<syntaxhighlight lang="asymptote">string text = "She was a soul stripper. She took my heart!";
string[][] remove = {{"a",""},{"e",""},{"i",""}};
 
for(var i : remove)
text = replace(text, remove);
}
write(text);</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">MsgBox % stripchars("She was a soul stripper. She took my heart!","aei")
 
StripChars(string, charsToStrip){
Line 646 ⟶ 699:
StringReplace, string, string, % A_LoopField, , All
return string
}</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|AWK}}==
<langsyntaxhighlight AWKlang="awk">#!/usr/bin/awk -f
BEGIN {
x = "She was a soul stripper. She took my heart!";
Line 657 ⟶ 710:
gsub(/[aei]/,"",x);
print x;
}</langsyntaxhighlight>
{{out}}
<pre>She was a soul stripper. She took my heart!
Line 664 ⟶ 717:
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="bacon">text$ = "She was a soul stripper. She took my heart!"
PRINT text$
PRINT EXTRACT$(text$, "[aei]", TRUE)
</syntaxhighlight>
</lang>
{{out}}
<pre>She was a soul stripper. She took my heart!
Line 675 ⟶ 728:
=={{header|BASIC}}==
{{works with|QBasic}}
<langsyntaxhighlight lang="qbasic">DECLARE FUNCTION stripchars$(src AS STRING, remove AS STRING)
 
PRINT stripchars$("She was a soul stripper. She took my heart!", "aei")
Line 693 ⟶ 746:
NEXT
stripchars$ = s
END FUNCTION</langsyntaxhighlight>
{{out}}
Sh ws soul strppr. Sh took my hrt!
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|BASIC}}
<syntaxhighlight lang="qbasic">100 cls
110 print stripchars$("She was a soul stripper. She took my heart!","aei")
120 sub stripchars$(src$,remove$)
130 s$ = src$
140 for l0 = 1 to len(remove$)
150 do
160 t = instr(s$,mid$(remove$,l0,1))
170 if t then
180 s$ = left$(s$,t-1)+mid$(s$,t+1)
190 else
200 exit do
210 endif
220 loop
230 next
240 stripchars$ = s$
250 end sub
260 end</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Stripchr.bas"
110 PRINT STRIPCHARS$("She was a soul stripper. She took my heart!","aei")
120 DEF STRIPCHARS$(SRC$,REMOVE$)
Line 710 ⟶ 786:
200 NEXT
210 LET STRIPCHARS$=T$
220 END DEF</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Works with 1k of RAM. Since the ZX81 character set includes neither lower case nor <tt>!</tt>, the test string is not quite identical to the one suggested in the specification.
<langsyntaxhighlight lang="basic"> 10 LET A$="SHE WAS A SOUL STRIPPER. SHE TOOK MY HEART."
20 LET B$="AEI"
30 GOSUB 60
Line 727 ⟶ 803:
120 LET C$=C$+A$(I)
130 NEXT I
140 RETURN</langsyntaxhighlight>
{{out}}
<pre>SH WS SOUL STRPPR. SH TOOK MY HRT.</pre>
Line 733 ⟶ 809:
 
See also: [[#Liberty BASIC|Liberty BASIC]], [[#PureBasic|PureBasic]]
 
=={{header|BASIC256}}==
<syntaxhighlight lang="basic256">function stripchars(texto, remove)
s = texto
for i = 1 to length(remove)
s = replace(s, mid(remove, i, 1), "", true) #true se puede omitir
next i
 
return s
end function
 
print stripchars("She was a soul stripper. She took my heart!", "aei")</syntaxhighlight>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> PRINT FNstripchars("She was a soul stripper. She took my heart!", "aei")
END
Line 747 ⟶ 835:
UNTIL C% = 0
NEXT
= A$</langsyntaxhighlight>
Output:
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let contains(str, chr) = valof
$( for i = 1 to str%0
if str%i = chr resultis true
resultis false
$)
 
let stripchars(str, chars, buf) = valof
$( buf%0 := 0
for i = 1 to str%0
if ~contains(chars, str%i)
$( buf%0 := buf%0 + 1
buf%(buf%0) := str%i
$)
resultis buf
$)
 
let start() be
$( let buf = vec 127
writef("%S*N",
stripchars("She was a soul stripper. She took my heart!",
"aei",
buf))
$)</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|BQN}}==
The key function here is set difference, which is <code>(¬∘∊/⊣)</code>.
 
<langsyntaxhighlight lang="bqn"> StripChars ← (¬∘∊/⊣)
¬∘∊/⊣
"She was a soul stripper. She took my heart!" StripChars "aei"
"Sh ws soul strppr. Sh took my hrt!"</langsyntaxhighlight>
 
=={{header|Bracmat}}==
This solution handles Unicode (utf-8) characters. Optimizations are: (1) the <code>chars</code> string is hard-coded into the pattern before the pattern is used in the match expression, (2) the output characters are stacked (cheap) rather than appended (expensive). The result string is obtained by stringizing the stack and reversing. To make multibyte characters survive, they are reversed before being put onto the stack. A problem is that this code is negligent of diacritical marks.
<langsyntaxhighlight lang="bracmat">( ( strip
= string chars s pat
. !arg:(?string.?chars)
Line 785 ⟶ 902:
& out
$ (strip$("Аппетит приходит во время еды".веп)
);</langsyntaxhighlight>
{{out}}
<pre>Атит риходит о рмя ды</pre>
Line 791 ⟶ 908:
=={{header|Burlesque}}==
 
<langsyntaxhighlight lang="burlesque">
blsq ) "She was a soul stripper. She took my heart!"{"aei"\/~[n!}f[
"Sh ws soul strppr. Sh took my hrt!"
</syntaxhighlight>
</lang>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Line 825 ⟶ 942:
free(new);
return 0;
}</langsyntaxhighlight>
{{out|Result}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
===With table lookup===
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 867 ⟶ 984:
 
return 0;
}</langsyntaxhighlight>Output same as above.
 
==={{header|Gadget}}===
 
<p>Gadget C-library:
[https://github.com/DanielStuardo/Gadget Gadget C-library in Github]
</p>
<syntaxhighlight lang="c">
#include <gadget/gadget.h>
 
LIB_GADGET_START
 
Main
String r, c = ".$%#\tEste@@@ mensaje será purgado!$$$", set = "$%#@.\t";
Stack{
Store ( r, Char_del( Upper( c ), set ) );
}Stack_off
 
Print "Original = [%s]\nChar deleted = [%s]\n", c, r;
Free secure r,c,set;
End
</syntaxhighlight>
{{out}}
<pre>
Original = [.$%# Este@@@ mensaje será purgado!$$$]
Char deleted = [ESTE MENSAJE SERÁ PURGADO!]
 
</pre>
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
 
public static string RemoveCharactersFromString(string testString, string removeChars)
Line 884 ⟶ 1,030:
}
return returnString;
}</langsyntaxhighlight>
Usage:
<langsyntaxhighlight Clang="c sharp">
using System;
 
Line 898 ⟶ 1,044:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Using <code>Regex</code>:
<langsyntaxhighlight Clang="c sharp">
using System;
using System.Text.RegularExpressions;
Line 910 ⟶ 1,056:
string pattern = "[" + removeChars + "]";
return Regex.Replace(testString, pattern, "");
}</langsyntaxhighlight>
 
<b>Alternative version</b> using <code>System.Span<T></code>:
<langsyntaxhighlight lang="csharp">using System;
 
public static System.ReadOnlySpan<T> RemoveItems<T>(System.Span<T> toStrip, System.ReadOnlySpan<T> toRemove)
Line 925 ⟶ 1,071:
 
return toStrip.Slice(toIndex);
}</langsyntaxhighlight>
Usage:
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 937 ⟶ 1,083:
System.Console.WriteLine(RemoveItems<char>(stripString.ToCharArray(), removeString).ToString());
}
}</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 943 ⟶ 1,089:
=={{header|C++}}==
{{works with|C++11}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <string>
Line 962 ⟶ 1,108:
std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 969 ⟶ 1,115:
 
=={{header|Clojure}}==
<langsyntaxhighlight Clojurelang="clojure">(defn strip [coll chars]
(apply str (remove #((set chars) %) coll)))
 
(strip "She was a soul stripper. She took my heart!" "aei")
;; => "Sh ws soul strppr. Sh took my hrt!"</langsyntaxhighlight>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">stripchars = proc (input, chars: string) returns (string)
result: array[char] := array[char]$[]
for c: char in string$chars(input) do
if string$indexc(c, chars) = 0 then
array[char]$addh(result, c)
end
end
return(string$ac2s(result))
end stripchars
 
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po,
stripchars("She was a soul stripper. She took my heart!", "aei"))
end start_up</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|COBOL}}==
This function takes the two arguments as specified in the task. However, the result will be returned in the string that had the characters stripped from it, and the string containing the characters to strip must be null-terminated (otherwise, a table would have to be used instead).
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Strip-Chars.
 
Line 1,023 ⟶ 1,188:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
<langsyntaxhighlight lang="cfm">
<Cfset theString = 'She was a soul stripper. She took my heart!'>
<Cfset theStrip = 'aei'>
Line 1,033 ⟶ 1,198:
</Cfloop>
<Cfoutput>#theString#</Cfoutput>
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun strip-chars (str chars)
(remove-if (lambda (ch) (find ch chars)) str))
 
Line 1,048 ⟶ 1,213:
" A string ")
;; => "A string"
</syntaxhighlight>
</lang>
 
=={{header|D}}==
This example shows both the functional and regex solutions.
<lang d>import std.stdio, std.string;
<syntaxhighlight lang="d">import std.stdio;
 
string stripchars(string s, string chars) {
import std.algorithm;
import std.conv;
return s.filter!(c => !chars.count(c)).to!string;
}
 
string stripchars2(string s, string chars) {
import std.regex;
return replaceAll(s, regex("[" ~ chars ~ "]"), "");
}
 
void main() {
autostring s = "She was a soul stripper. She took my heart!";
string chars = "aei";
auto ss = "Sh ws soul strppr. Sh took my hrt!";
 
assert(s.removechars("aei") == ss);
writeln(stripchars(s, chars));
}</lang>
writeln(stripchars2(s, chars));
}</syntaxhighlight>
 
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!
Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program StripCharacters;
 
{$APPTYPE CONSOLE}
Line 1,080 ⟶ 1,263:
Writeln(TEST_STRING);
Writeln(StripChars(TEST_STRING, 'aei'));
end.</langsyntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">\util.g
 
proc nonrec stripchars(*char str, chars, outbuf) *char:
channel input text ch_in;
channel output text ch_out;
[2]char cur = ('\e', '\e');
open(ch_in, str);
open(ch_out, outbuf);
while read(ch_in; cur[0]) do
if CharsIndex(chars, &cur[0]) = -1 then
write(ch_out; cur[0])
fi
od;
close(ch_in);
close(ch_out);
outbuf
corp
 
proc nonrec main() void:
[128]char buf;
writeln(
stripchars("She was a soul stripper. She took my heart!",
"aei", &buf[0]))
corp</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|EasyLang}}==
 
<syntaxhighlight>
func$ strip s$ del$ .
for c$ in strchars s$
if strpos del$ c$ <> 0
c$ = ""
.
r$ &= c$
.
return r$
.
print strip "She was a soul stripper. She took my heart!" "aei"
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
;; using regexp /[chars]/g
 
Line 1,091 ⟶ 1,318:
(strip-chars "She was a soul stripper. She took my heart!" "aei")
→ "Sh ws soul strppr. Sh took my hrt!"
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import extensions;
import extensions'text;
import system'routines;
Line 1,104 ⟶ 1,331:
var removeChars := "aei";
console.printLine(testString.filterBy::(ch => removeChars.indexOf(0, ch) == -1).summarize(new StringWriter()))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,113 ⟶ 1,340:
=={{header|Elixir}}==
The easiest solution would be to use replace from the String module, which takes a Regex.
<langsyntaxhighlight lang="elixir">str = "She was a soul stripper. She took my heart!"
String.replace(str, ~r/[aei]/, "")
# => Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
To get the desired interface, we just have to dynamically construct the Regex:
<langsyntaxhighlight lang="elixir">defmodule RC do
def stripchars(str, chars) do
String.replace(str, ~r/[#{chars}]/, "")
Line 1,126 ⟶ 1,353:
str = "She was a soul stripper. She took my heart!"
RC.stripchars(str, "aei")
# => Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(defun stripchars (s chars)
(seq-into
(seq-filter (lambda (x) (not (seq-contains chars x))) s)
'string))
 
(stripchars "She was a soul stripper. She took my heart!" "aei")
</syntaxhighlight>
 
{{out}}
 
<pre>
"Sh ws soul strppr. Sh took my hrt!"
</pre>
 
=={{header|Erlang}}==
Line 1,146 ⟶ 1,389:
The work of this task is done by the <code>transmute</code> function; this function takes parameters separated by commas. Here it uses 3 parameters, up to 5, the other two are optional and aren't put in this time.
The <code>transmute</code> function's usage and examples can be searched for in the official Euphoria 4.0.0+ manual. Euphoria object identifiers (names) are case sensitive but don't need to be in a particular case to be recognized as an object type.
<langsyntaxhighlight lang="euphoria">include std\sequence.e
include std\console.e
 
Line 1,153 ⟶ 1,396:
originalString = transmute(originalString, {{} , "a", "e", "i"}, {{} , "", "", ""})
puts(1,"After : " & originalString & "\n")
any_key()</langsyntaxhighlight>
{{out}}
<pre>Before : She was a soul stripper. She took my heart!
Line 1,167 ⟶ 1,410:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang="lisp">exceptChars
=LAMBDA(excluded,
LAMBDA(src,
Line 1,182 ⟶ 1,425:
)
)
)</langsyntaxhighlight>
 
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<langsyntaxhighlight lang="lisp">CHARSROW
=LAMBDA(s,
MID(s,
Line 1,200 ⟶ 1,443:
FILTER(xs, p(xs))
)
)</langsyntaxhighlight>
 
{{Out}}
Line 1,222 ⟶ 1,465:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
<lang fsharp>let stripChars text (chars:string) =
let stripChars text (chars:string) =
Array.fold (
Seq.fold (
fun (s:string) c -> s.Replace(c.ToString(),"")
) text (chars.ToCharArray())
printfn "%s" (stripChars "She was a soul stripper. She took my heart!" "aei")
 
</syntaxhighlight>
[<EntryPoint>]
{{out}}
let main args =
<pre>
printfn "%s" (stripChars "She was a soul stripper. She took my heart!" "aei")
Sh ws soul strppr. Sh took my hrt!</pre>
0</lang>
</pre>
Output
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang ="factor">without</langsyntaxhighlight>
Example:
<langsyntaxhighlight lang="factor">USE: sets
"She was a soul stripper. She took my heart!" "aei" without print</langsyntaxhighlight>
{{out}}
<pre>
Line 1,249 ⟶ 1,492:
character by character in a memory buffer called PAD. PAD is a standard Forth word.
SCAN is common in most Forth systems and is typically coded in Forth assembler
<langsyntaxhighlight Forthlang="forth">: append-char ( char str -- ) dup >r count dup 1+ r> c! + c! ; \ append char to a counted string
: strippers ( -- addr len) s" aeiAEI" ; \ a string literal returns addr and length
 
Line 1,264 ⟶ 1,507:
2drop \ we don't need STRIPPERS now
PAD count ; \ return PAD address and length
</syntaxhighlight>
</lang>
Test at the forth console
<pre>strippers s" She was a soul stripper. She took my heart!" stripchars cr type
Line 1,273 ⟶ 1,516:
This shorter version removes creating a new string and prints the "stripped" string immediately.
The macro called '?exit' speeds up the '.stripped' print loop by compiling its code inside the loop.
<langsyntaxhighlight Forthlang="forth">: ?exit ( c1 c2 -- ) ]] = if drop unloop exit then [[ ; immediate
: .stripped ( a u c -- ) -rot bounds ?do dup i c@ ?exit loop emit ;
: stripchars ( a1 u1 a2 u2 -- ) bounds ?do 2dup i c@ .stripped loop 2drop ;
Line 1,279 ⟶ 1,522:
: "aei" s" aei" ;
 
\ usage: "aei" s" She was a soul stripper. She took my heart!" stripchars</langsyntaxhighlight>
 
=={{header|Fortran}}==
<langsyntaxhighlight Fortranlang="fortran">elemental subroutine strip(string,set)
character(len=*), intent(inout) :: string
character(len=*), intent(in) :: set
Line 1,298 ⟶ 1,541:
end if
end do
end subroutine strip</langsyntaxhighlight>Note: Since strip is an elemental subroutine, it can be called with arrays of strings as well.
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Function stripChars(s As Const String, chars As Const String) As String
Line 1,333 ⟶ 1,576:
Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 1,341 ⟶ 1,584:
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">stripchars[str, remove] :=
{
set = toSet[chars[remove]]
Line 1,348 ⟶ 1,591:
 
println[stripchars["She was a soul stripper. She took my heart!","aei"]]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,356 ⟶ 1,599:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Strip_a_set_of_characters_from_a_string}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Strip a set of characters from a string 01.png]]
In '''[https://formulae.org/?example=Strip_a_set_of_characters_from_a_string this]''' page you can see the program(s) related to this task and their results.
 
'''Test case'''
 
[[File:Fōrmulæ - Strip a set of characters from a string 02.png]]
 
[[File:Fōrmulæ - Strip a set of characters from a string 03.png]]
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1, @"Strip a set of characters from a string"
 
local fn StringByStrippingCharacters( string as CFStringRef, chrs as CFStringRef ) as CFStringRef
end fn = fn ArrayComponentsJoinedByString( fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetWithCharactersInString( chrs ) ), @"" )
 
CFStringRef string, chrs
 
string = @"She was a soul stripper. She took my heart!"
chrs = @"aei"
 
print string
print fn StringByStrippingCharacters( string, chrs )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
She was a soul stripper. She took my heart!
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=f199a8f7a56cf466e4a16c3fc71f6278 Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
 
Print StripChars("She was a soul stripper. She took my heart!", "aei")
Line 1,379 ⟶ 1,649:
Return sText
 
End</langsyntaxhighlight>
Output:
<pre>
Line 1,386 ⟶ 1,656:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,405 ⟶ 1,675:
fmt.Println(stripchars("She was a soul stripper. She took my heart!",
"aei"))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,413 ⟶ 1,683:
=={{header|Groovy}}==
Solution:
<langsyntaxhighlight lang="groovy">def stripChars = { string, stripChars ->
def list = string as List
list.removeAll(stripChars as List)
list.join()
}</langsyntaxhighlight>
Test:
<langsyntaxhighlight lang="groovy">println (stripChars('She was a soul stripper. She took my heart!', 'aei'))</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 1,425 ⟶ 1,695:
=={{header|Haskell}}==
I decided to make the string the second argument and the characters the first argument, because it is more likely for someone to partially apply the characters to be stripped (making a function that strips certain characters), than the string.
<langsyntaxhighlight lang="haskell">stripChars :: String -> String -> String
stripChars = filter . flip notElem</langsyntaxhighlight>
{{out|Testing in GHCI}}
<pre>> stripChars "aei" "She was a soul stripper. She took my heart!"
Line 1,433 ⟶ 1,703:
=={{header|Icon}} and {{header|Unicon}}==
The following works in both languages:
<langsyntaxhighlight 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
Line 1,442 ⟶ 1,712:
s ? while ns ||:= (not pos(0), tab(upto(cs)|0)) do tab(many(cs))
return ns
end</langsyntaxhighlight>
{{out|Sample runs}}
<pre>->strip
Line 1,453 ⟶ 1,723:
rdvrks r nt trs.
-></pre>
 
=={{header|Insitux}}==
{{Trans|Clojure}}
<syntaxhighlight lang="insitux">(function strip from what
(remove (to-vec what) from))
 
(strip "She was a soul stripper. She took my heart!" "aei")
;returns "Sh ws soul strppr. Sh took my hrt!"</syntaxhighlight>
 
=={{header|J}}==
Line 1,458 ⟶ 1,736:
The dyadic primitive <code>-.</code> ([http://www.jsoftware.com/help/dictionary/d121.htm Less]) is probably the simplest way to solve this task.
{{out|Example Usage}}
<langsyntaxhighlight lang="j"> 'She was a soul stripper. She took my heart!' -. 'aei'
Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
=={{header|Java}}==
The most basic approach is to use the ''String.replace'' method.
<lang Java>class StripChars {
<syntaxhighlight lang="java">
public static String stripChars(String inString, String toStrip) {
String stripCharacters(String string, String characters) {
return inString.replaceAll("[" + toStrip + "]", "");
for (char character : characters.toCharArray())
string = string.replace(String.valueOf(character), "");
return string;
}
</syntaxhighlight>
You could also use a ''StringBuilder'' which provides a ''deleteCharAt'' method.
<syntaxhighlight lang="java">
String stripCharacters(String string, String characters) {
StringBuilder stripped = new StringBuilder(string);
/* traversing the string backwards is necessary to avoid collision */
for (int index = string.length() - 1; index >= 0; index--) {
if (characters.contains(String.valueOf(string.charAt(index))))
stripped.deleteCharAt(index);
}
return stripped.toString();
 
}
public static void main(String[] args) {
</syntaxhighlight>
String sentence = "She was a soul stripper. She took my heart!";
You could use the ''String.replaceAll'' method, which takes a regular expression as it's first argument.
String chars = "aei";
<syntaxhighlight lang="java">
System.out.println("sentence: " + sentence);
static String stripCharacters(String string, String characters) {
System.out.println("to strip: " + chars);
/* be sure to 'quote' the 'characters' to avoid pattern collision */
System.out.println("stripped: " + stripChars(sentence, chars));
characters = Pattern.quote(characters);
}
string = string.replaceAll("[%s]".formatted(characters), "");
}</lang>
return string;
{{out}}
}
<pre>sentence: She was a soul stripper. She took my heart!
</syntaxhighlight>
to strip: aei
These will all produce the following string.
stripped: Sh ws soul strppr. Sh took my hrt!</pre>
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|JavaScript}}==
Line 1,484 ⟶ 1,778:
===ES5===
 
<langsyntaxhighlight JavaScriptlang="javascript">function stripchars(string, chars) {
return string.replace(RegExp('['+chars+']','g'), '');
}</langsyntaxhighlight>
 
===ES6===
Line 1,492 ⟶ 1,786:
Reversing the order of the arguments, to simplify any currying:
 
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 1,512 ⟶ 1,806:
 
// 'Sh ws soul strppr. Sh took my hrt!'
})();</langsyntaxhighlight>
 
{{Out}}
Line 1,519 ⟶ 1,813:
Alternatively, we could also do this without a regex:
 
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 1,545 ⟶ 1,839:
 
// 'Sh ws soul strppr. Sh took my hrt!'
})();</langsyntaxhighlight>
 
{{Out}}
<pre>'Sh ws soul strppr. Sh took my hrt!'</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE stripchars == [in not] cons filter.
 
"She was a soul stripper. She took my heart!" "aei" stripchars.</syntaxhighlight>
{{out}}
<pre>"Sh ws soul strppr. Sh took my hrt!"</pre>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq">def stripchars(string; banish):
(string | explode) - (banish | explode) | implode;</langsyntaxhighlight>
'''Note''': In jq, it would be more idiomatic to define the function as a filter:
<langsyntaxhighlight lang="jq">def stripchars(banish):
explode - (banish | explode) | implode;</langsyntaxhighlight>
In this case, we would write:
"She was a soul stripper. She took my heart!" | stripchars("aei")
Line 1,562 ⟶ 1,863:
{{works with|Julia|1.0}}
 
<langsyntaxhighlight lang="julia">stripChar = (s, r) -> replace(s, Regex("[$r]") => "")</langsyntaxhighlight>
 
{{out}}
Line 1,568 ⟶ 1,869:
Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|KotlinK}}==
<syntaxhighlight lang="k">"She was a soul stripper. She took my heart!" ^ "aei"</syntaxhighlight>
<lang scala>// version 1.0.6
{{out}}
<pre>"Sh ws soul strppr. Sh took my hrt!"</pre>
 
=={{header|Kotlin}}==
fun stripChars(s: String, r: String) = s.replace(Regex("[$r]"), "")
<syntaxhighlight lang="kotlin">fun stripChars(s: String, r: String) = s.filter { it !in r }
 
fun main(args: Array<String>) {
println(stripChars("She was a soul stripper. She took my heart!", "aei"))
}</langsyntaxhighlight>
 
{{out}}
Line 1,584 ⟶ 1,888:
=={{header|Lambdatalk}}==
Text substitutions are easy to process directly using regular expressions :
<langsyntaxhighlight lang="scheme">
{S.replace (a|e|i)
by // nothing
in She was a soul stripper. She took my heart!}
-> Sh ws soul strppr. Sh took my hrt!
</syntaxhighlight>
</lang>
and can be wrapped inside a fuction:
<langsyntaxhighlight lang="scheme">
{def word2rex
{def word2rex.r
Line 1,605 ⟶ 1,909:
She was a soul stripper. She took my heart!}
-> Sh ws soul strppr. Sh took my hrt!
</syntaxhighlight>
</lang>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">define stripper(in::string,destroy::string) => {
with toremove in #destroy->values do => {
#in->replace(#toremove,'')
Line 1,614 ⟶ 1,918:
return #in
}
stripper('She was a soul stripper. She took my heart!','aei')</langsyntaxhighlight>
 
{{out}}
Line 1,620 ⟶ 1,924:
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">Print stripchars$("She was a soul stripper. She took my heart!", "aei", 1)
End
 
Line 1,630 ⟶ 1,934:
Next i
If (num <= Len(chars$)) Then stripchars$ = stripchars$(stripchars$, chars$, (num + 1))
End Function</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">function stripChars str charlist
local strstripped
put str into strstripped
Line 1,640 ⟶ 1,944:
end repeat
return strstripped
end stripChars</langsyntaxhighlight>
Test<langsyntaxhighlight LiveCodelang="livecode">command teststripchars
put stripchars("She was a soul stripper. She took my heart!","aei")
end teststripchars</langsyntaxhighlight>Output<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">to strip :string :chars
output filter [not substringp ? :chars] :string
end
Line 1,652 ⟶ 1,956:
print strip "She\ was\ a\ soul\ stripper.\ She\ took\ my\ heart! "aei
 
bye</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">
function stripchars(str, chrs)
local s = str:gsub("["..chrs:gsub("%W","%%%1").."]", '')
Line 1,667 ⟶ 1,971:
print( stripchars( "She was a soul stripper. She took my heart!", "a-z" ) )
--> She ws soul stripper. She took my hert!
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">with(StringTools):
 
Remove(c->Has("aei",c), "She was a soul stripper. She took my heart!");</langsyntaxhighlight>
Output:
<pre> "Sh ws soul strppr. Sh took my hrt!"</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">stripchars[a_,b_]:=StringReplace[a,(#->"")&/@Characters[b]]
stripchars["She was a soul stripper. She took my heart!","aei"]
->Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight MATLABlang="matlab">function str = stripchars(str, charlist)
% MATLAB after 2016b: str = erase(str, charlist);
str(ismember(str, charlist)) = '';</langsyntaxhighlight>
{{out}}
<pre> >> stripchars('She was a soul stripper. She took my heart!','aei')
Line 1,690 ⟶ 1,994:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">def stripchars(string, chars)
for char in chars
string = string.replace(char, "")
end
return string
end</langsyntaxhighlight>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">StripChars( text : string, remove : string ) : string
{
def chuck = Explode(remove);
Concat( "", Split(text, chuck))
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
 
options replace format comments java crossref savelog symbols
Line 1,720 ⟶ 2,024:
end c_
 
return haystack</langsyntaxhighlight>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(let (sentence "She was a soul stripper. She took my heart!")
(replace "[aei]" sentence "" 0))</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import strutils
 
echo "She was a soul stripper. She took my heart!".split({'a','e','i'}).join()
Line 1,741 ⟶ 2,045:
echo "She was a soul stripper. She took my heart!".filterIt(it notin "aei").join()
 
</syntaxhighlight>
</lang>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!
Line 1,750 ⟶ 2,054:
{{works with|Mac OS X|10.5+}}
{{works with|iOS|1.0}}
<langsyntaxhighlight lang="objc">@interface NSString (StripCharacters)
- (NSString *) stripCharactersInSet: (NSCharacterSet *) chars;
@end
Line 1,758 ⟶ 2,062:
return [[self componentsSeparatedByCharactersInSet:chars] componentsJoinedByString:@""];
}
@end</langsyntaxhighlight>
{{out|To use}}
<langsyntaxhighlight lang="objc"> NSString *aString = @"She was a soul stripper. She took my heart!";
NSCharacterSet* chars = [NSCharacterSet characterSetWithCharactersInString:@"aei"];
 
// Display the NSString.
NSLog(@"%@", [aString stripCharactersInSet:chars]);</langsyntaxhighlight>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let stripchars s cs =
let len = String.length s in
let res = Bytes.create len in
Line 1,780 ⟶ 2,084:
end
in
aux 0 0</langsyntaxhighlight>
{{out|Testing in the toplevel}}
<pre># stripchars "She was a soul stripper. She took my heart!" "aei" ;;
Line 1,787 ⟶ 2,091:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">String method: stripChars(str) #[ str include not ] self filter ;
 
"She was a soul stripper. She took my heart!" stripChars("aei") println</langsyntaxhighlight>
 
{{out}}
Line 1,798 ⟶ 2,102:
=={{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>...
<langsyntaxhighlight lang="parigp">stripchars(s, bad)={
bad=Set(Vec(Vecsmall(bad)));
s=Vecsmall(s);
Line 1,805 ⟶ 2,109:
Strchr(v)
};
stripchars("She was a soul stripper. She took my heart!","aei")</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,812 ⟶ 2,116:
=={{header|Perl}}==
Note: this example uses a regular expression character class. Certain characters, like hyphens and brackets, may need to be escaped.
<langsyntaxhighlight lang="perl">sub stripchars {
my ($s, $chars) = @_;
$s =~ s/[$chars]//g;
Line 1,818 ⟶ 2,122:
}
 
print stripchars("She was a soul stripper. She took my heart!", "aei"), "\n";</langsyntaxhighlight>
{{out}}
<pre>
Line 1,824 ⟶ 2,128:
</pre>
Another good option for stripping characters is to use the <code>tr///</code> operator. This option is very efficient when the set of characters to strip is fixed at compile time, because <code>tr///</code> is specifically designed for transforming and deleting characters. Note that hyphens also have special meaning in this case.
<langsyntaxhighlight lang="perl">$str =~ tr/aei//d;</langsyntaxhighlight>
Since the characters used for <code>tr///</code> must be fixed at compile time, unfortunately, it requires the use of an <code>eval</code> to do this generally for any set of characters provided at runtime:
<langsyntaxhighlight lang="perl">sub stripchars {
my ($s, $chars) = @_;
eval("\$s =~ tr/$chars//d;");
return $s;
}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"She was a soul stripper. She took my heart!"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"out"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"aei"</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,843 ⟶ 2,147:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
function stripchars($s, $chars) {
return str_replace(str_split($chars), "", $s);
Line 1,849 ⟶ 2,153:
 
echo stripchars("She was a soul stripper. She took my heart!", "aei"), "\n";
?></langsyntaxhighlight>
{{out}}
<pre>
Line 1,857 ⟶ 2,161:
=={{header|Picat}}==
===List comprehension===
<langsyntaxhighlight Picatlang="picat">stripchars(String, Chars) = [C : C in String, not(membchk(C,Chars))].</langsyntaxhighlight>
 
===Recursion===
<langsyntaxhighlight Picatlang="picat">stripchars2(String,Chars, Res) =>
stripchars2(String, Chars, [], Res).
 
Line 1,868 ⟶ 2,172:
stripchars2(T, Chars, Res1, Res).
stripchars2([H|T], Chars, Res1, [H|Res]) :-
stripchars2(T, Chars, Res1, Res).</langsyntaxhighlight>
 
===Test===
<langsyntaxhighlight Picatlang="picat">go =>
S = "She was a soul stripper. She took my heart!",
println(stripchars(S, "aei")),
stripchars2(S, "aei", S2),
println(S2),
nl.</langsyntaxhighlight>
 
 
Line 1,884 ⟶ 2,188:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de strDiff (Str1 Str2)
(pack (diff (chop Str1) (chop Str2))) )</langsyntaxhighlight>
{{out}}
<pre>: (strDiff "She was a soul stripper. She took my heart!" "aei")
Line 1,891 ⟶ 2,195:
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">strip_chars: procedure (text, chars) returns (character (100) varying);
declare text character (*) varying, chars character (*) varying;
declare out_text character (100);
Line 1,904 ⟶ 2,208:
end;
return (substr(out_text, 1, j) );
end strip_chars;</langsyntaxhighlight>
 
=={{header|PL/M}}==
<syntaxhighlight lang="pli">100H:
BDOS: PROCEDURE(F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; GO TO 0; END EXIT;
PRINT: PROCEDURE(S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
DECLARE TRUE LITERALLY '0FFH', FALSE LITERALLY '0';
 
/* SEE IF STRING CONTAINS CHARACTER */
CONTAINS: PROCEDURE(STR, CHR) BYTE;
DECLARE STR ADDRESS, (SCH BASED STR, CHR) BYTE;
DO WHILE SCH <> '$';
IF SCH = CHR THEN RETURN TRUE;
STR = STR + 1;
END;
RETURN FALSE;
END CONTAINS;
 
/* STRIP CHARACTERS FROM A STRING */
STRIP$CHARS: PROCEDURE(STR, CHARS, OUTBUF);
DECLARE (STR, CHARS, OUTBUF) ADDRESS;
DECLARE (IN$CH BASED STR, OUT$CH BASED OUTBUF) BYTE;
DO WHILE IN$CH <> '$';
IF NOT CONTAINS(CHARS, IN$CH) THEN DO;
OUT$CH = IN$CH;
OUTBUF = OUTBUF + 1;
END;
STR = STR + 1;
END;
OUT$CH = '$';
END STRIP$CHARS;
 
/* TEST */
DECLARE BUF (128) ADDRESS;
 
/* 8080 PL/M DOES NOT SUPPORT LOWERCASE OR EXCLAMATION MARK */
CALL STRIP$CHARS(
.'SHE WAS A SOUL STRIPPER. SHE TOOK MY HEART.$',
.'AEI$',
.BUF);
CALL PRINT(.BUF);
CALL EXIT;
EOF</syntaxhighlight>
{{out}}
<pre>SH WS SOUL STRPPR. SH TOOK MY HRT.</pre>
 
=={{header|Powershell}}==
Powershell have replace operator that by will replace a regex pattern with a given string:
 
<langsyntaxhighlight Powershelllang="powershell">'She was a soul stripper. She took my heart!' -replace '[aei]', ''
Sh ws soul strppr. Sh took my hrt!
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
Works with SWI-Prolog and module '''lambda.pl''' written by '''Ulrich Neumerkel''' found there http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/lambda.pl .
<langsyntaxhighlight Prologlang="prolog">:- use_module(library(lambda)).
 
stripchars(String, Exclude, Result) :-
exclude(\X^(member(X, Exclude)), String, Result1),
string_to_list(Result, Result1).
</syntaxhighlight>
</lang>
{{out}}
<pre> ?- stripchars("She was a soul stripper. She took my heart!","aei", R).
Line 1,928 ⟶ 2,277:
=== alternative version using DCG strings ===
 
<langsyntaxhighlight lang="prolog">
:- system:set_prolog_flag(double_quotes,chars) .
 
Line 1,954 ⟶ 2,303:
strip_chars(SOURCEz0,SETz0)
.
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,964 ⟶ 2,313:
=={{header|PureBasic}}==
PureBasic uses a single (for ASCII) or a two-byte (for Unicode) null to signal the end of a string. Nulls are thus excluded from the allowable characters to strip as they can't be included in a PureBasic string.
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.s stripChars(source.s, charsToStrip.s)
Protected i, *ptrChar.Character, length = Len(source), result.s
*ptrChar = @source
Line 1,981 ⟶ 2,330:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 1,988 ⟶ 2,337:
===Not using regular expressions===
{{works with|Python|2.6+}}
<langsyntaxhighlight lang="python">>>> def stripchars(s, chars):
... return s.translate(None, chars)
...
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws soul strppr. Sh took my hrt!'</langsyntaxhighlight>
{{works with|Python|2.x}}
<langsyntaxhighlight lang="python">>>> import string
>>> def stripchars(s, chars):
... return s.translate(string.maketrans("", ""), chars)
...
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws soul strppr. Sh took my hrt!'</langsyntaxhighlight>
Implemented manually:
<langsyntaxhighlight lang="python">>>> def stripchars(s, chars):
... return "".join(c for c in s if c not in chars)
...
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws soul strppr. Sh took my hrt!'</langsyntaxhighlight>
===Using regular expressions===
<langsyntaxhighlight lang="python">>>> import re
>>> def stripchars(s, chars):
return re.sub('[%s]+' % re.escape(chars), '', s)
Line 2,013 ⟶ 2,362:
>>> stripchars("She was a soul stripper. She took my heart!", "aei")
'Sh ws soul strppr. Sh took my hrt!'
>>> </langsyntaxhighlight>
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ $ "" swap witheach [ upper join ] ] is upper$ ( $ --> $ )
 
[ $ "" swap witheach [ lower join ] ] is lower$ ( $ --> $ )
Line 2,033 ⟶ 2,382:
 
$ "One is never alone with a rubber duck." dup echo$ cr
$ "EIU" strip$ echo$ cr</langsyntaxhighlight>
 
{{out}}
Line 2,042 ⟶ 2,391:
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 2,053 ⟶ 2,402:
(define (stripchars2 text chars)
(regexp-replace* (~a "[" chars "]+") text ""))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>sub strip_chars ( $s, $chars ) {
return $s.trans( $chars.comb X=> '' );
}
 
say strip_chars( 'She was a soul stripper. She took my heart!', 'aei' );</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Red}}==
<syntaxhighlight lang="red">
<lang Red>
stripchars: func [str chars] [trim/with str chars]
stripchars "She was a soul stripper. She took my heart!" "aei"</langsyntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Strip ('aei') 'She was a soul stripper. She took my heart!'>>;
};
 
Strip {
(e.Chs) = ;
(e.Chs) s.C e.S, e.Chs: e.1 s.C e.2 = <Strip (e.Chs) e.S>;
(e.Chs) s.C e.S = s.C <Strip (e.Chs) e.S>;
};</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|REXX}}==
===version 1===
In the REXX language, '''strip''' usually means to remove leading and/or trailing characters from a string (most often, blanks).
<langsyntaxhighlight lang="rexx">/*REXX program removes a list of characters from a string (the haystack). */
say stripChars('She was a soul stripper. She took my heart!', "iea") /*elide: iea */
exit /*stick a fork in it, we're all done. */
Line 2,081 ⟶ 2,443:
haystack=changestr( substr( remove, j, 1), haystack, '')
end /*j*/
return haystack</langsyntaxhighlight>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, so one is included here &nbsp; ───► &nbsp; [[CHANGESTR.REX]].
<br><br>
Line 2,091 ⟶ 2,453:
===version 2===
Using recursion:
<langsyntaxhighlight lang="rexx">/* REXX */
say StripChars('She was a soul stripper. She took my heart!','iea')
exit 0
Line 2,100 ⟶ 2,462:
if removepos=0 then return strng
parse value strng with strng =(removepos) +1 rest
return strng || StripChars(rest,remove)</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hart!rt!</pre>
Line 2,107 ⟶ 2,469:
This works on all Rexxes.
<br>(Except for R4 and ROO at the least, there may be others.)
<langsyntaxhighlight lang="rexx">
/* REXX ***************************************************************
* If source and stripchars don't contain a hex 00 character, this works
Line 2,122 ⟶ 2,484:
result=space(result,0,' ') /* remove all blanks */
Return translate(result,' ','00'x) /* '00'x back to blanks */
</syntaxhighlight>
</lang>
 
===version 4===
Another neat (?) one
No x00 restriction and no changestr
<langsyntaxhighlight lang="rexx">
stripchars: Procedure
Parse Arg i,s /* get input and chars to be removed */
Line 2,137 ⟶ 2,499:
End
Return o /* return the result */
</syntaxhighlight>
</lang>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
aList = "She was a soul stripper. She took my heart!"
bList = "aei"
Line 2,151 ⟶ 2,513:
next
return cList
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
≪ → string out
≪ "" 1 string SIZE '''FOR''' j
string j DUP SUB
'''IF''' out OVER POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT'''
≫ ≫ 'STRIP' STO
{{in}}
<pre>
"She was a soul stripper. She took my heart!" "aei" STRIP
</pre>
{{in}}
<pre>
1: "Sh ws soul strppr. Sh took my hrt!"
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">"She was a soul stripper. She took my heart!".delete("aei") # => "Sh ws soul strppr. Sh took my hrt!"</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">function stripchars(texto, remove)
s = texto
for i = 1 to length(remove)
s = replace(s, mid(remove, i, 1), "", true)
next i
 
return s
end function</syntaxhighlight>
 
=={{header|Rust}}==
Naive Implementation:
<langsyntaxhighlight lang="rust">
fn strip_characters(original : &str, to_strip : &str) -> String {
let mut result = String::new();
Line 2,168 ⟶ 2,556:
result
}
</syntaxhighlight>
</lang>
 
Functional Implementation:
<langsyntaxhighlight lang="rust">
fn strip_characters(original : &str, to_strip : &str) -> String {
original.chars().filter(|&c| !to_strip.contains(c)).collect()
}
</syntaxhighlight>
</lang>
 
Either can be executed thusly:
<langsyntaxhighlight lang="rust">
fn main() {
println!("{}", strip_characters("She was a soul stripper. She took my heart!", "aei"));
}
</syntaxhighlight>
</lang>
 
=={{header|SAS}}==
This code will write the resulting string to the log:
<langsyntaxhighlight SASlang="sas">%let string=She was a soul stripper. She took my heart!;
%let chars=aei;
%let stripped=%sysfunc(compress("&string","&chars"));
%put &stripped;</langsyntaxhighlight>
 
Log:
<langsyntaxhighlight SASlang="sas">Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
=={{header|S-BASIC}}==
<syntaxhighlight lang="BASIC">
rem - strip unwanted characters from a string
function strip(s, unwanted = string) = string
var i = integer
var outstr = string
var ch = char
outstr = ""
for i = 1 to len(s)
ch = mid(s, i, 1)
if instr(1, unwanted, ch) = 0 then
outstr = outstr + ch
next i
end = outstr
 
rem - exercise the routine
print strip("She was a soul stripper. She took my heart!","aei")
 
end
</syntaxhighlight>
{{out}}
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">def stripChars(s:String, ch:String)= s filterNot (ch contains _)
 
stripChars("She was a soul stripper. She took my heart!", "aei")
// => Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 2,205 ⟶ 2,618:
The second uses the SRFI libraries to create a character set and delete those characters from the string.
 
<langsyntaxhighlight lang="scheme">
(import (scheme base)
(scheme write)
Line 2,233 ⟶ 2,646:
(display (strip-chars2 "She was a soul stripper. She took my heart!" "aei"))
(newline)
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,242 ⟶ 2,655:
 
=={{header|ScriptBasic}}==
<langsyntaxhighlight lang="scriptbasic">
str1 = "She was a soul stripper. She took my heart!"
rmv = "aei"
Line 2,249 ⟶ 2,662:
NEXT
PRINT str1,"\n"
</syntaxhighlight>
</lang>
 
=={{header|Sed}}==
Using echo and piping it through a sed filter:
<langsyntaxhighlight lang="bash">#!/bin/bash
 
strip_char()
{
echo "$1" | sed "s/[$2]//g"
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func string: stripchars (in string: mainStri, in string: charList) is func
Line 2,278 ⟶ 2,691:
begin
writeln(stripchars("She was a soul stripper. She took my heart!", "aei"));
end func;</langsyntaxhighlight>
{{out}}
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program strip_chars;
print(strip("She was a soul stripper. She took my heart!", "aei"));
 
proc strip(s, chs);
return +/[c : c in s | not c in chs];
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func stripchars(str, char_list) {
str.tr(char_list, "", "d");
}</langsyntaxhighlight>
 
or:
<langsyntaxhighlight lang="ruby">func stripchars(str, char_list) {
str.chars.grep {|c| !char_list.contains(c)}.join;
}</langsyntaxhighlight>
 
Calling the function:
<langsyntaxhighlight lang="ruby">say stripchars("She was a soul stripper. She took my heart!", "aei");</langsyntaxhighlight>
{{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}}==
{{works with|Pharo|1.3-13315}}
<langsyntaxhighlight lang="smalltalk">| stripChars |
stripChars := [ :string :chars |
string reject: [ :c | chars includes: c ] ].
Line 2,308 ⟶ 2,751:
value: 'aei'.
 
"'Sh ws soul strppr. Sh took my hrt!'"</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Note: "strip" is a function, its argument, the label of its first executed line, and its returned value.
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> DEFINE("strip(strip,c)") :(strip_end)
strip strip ANY(c) = :S(strip)F(RETURN)
strip_end
Line 2,321 ⟶ 2,764:
again line = INPUT :F(END)
OUTPUT = strip(line, chars) :(again)
END</langsyntaxhighlight>
{{out}}
<pre>snobol4 strip.sno aei
Line 2,328 ⟶ 2,771:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">fun stripchars (string, chars) = let
fun aux c =
if String.isSubstring (str c) chars then
Line 2,336 ⟶ 2,779:
in
String.translate aux string
end</langsyntaxhighlight>
{{out|Testing}}
<pre>- stripchars ("She was a soul stripper. She took my heart!", "aei") ;
val it = "Sh ws soul strppr. Sh took my hrt!" : string</pre>
Alternately:
<langsyntaxhighlight lang="sml">fun stripchars (string, chars) =
String.concat (String.tokens (fn c => String.isSubstring (str c) chars) string)</langsyntaxhighlight>
{{out|Testing}}
<pre>- stripchars ("She was a soul stripper. She took my heart!", "aei") ;
val it = "Sh ws soul strppr. Sh took my hrt!" : string</pre>
 
=={{header|Stringle}}==
<syntaxhighlight lang="stringle">a "She was a soul stripper. She took my heart!"
b "aei"
#a
c c .a
b %.\c #c #:c
a :a
#a
$ c
</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">extension String {
func stripCharactersInSet(chars: [Character]) -> String {
return String(seq: filter(self) {find(chars, $0) == nil})
Line 2,357 ⟶ 2,813:
let chars: [Character] = ["a", "e", "i"]
 
println(aString.stripCharactersInSet(chars))</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc stripchars {str chars} {
foreach c [split $chars ""] {set str [string map [list $c ""] $str]}
return $str
Line 2,368 ⟶ 2,824:
 
set s "She was a soul stripper. She took my heart!"
puts [stripchars $s "aei"]</langsyntaxhighlight>
 
=={{header|TorqueScript}}==
Line 2,382 ⟶ 2,838:
She was a soul stripper. She took my heart!
Sh ws soul strppr. Sh took my hrt!
 
=={{header|Transd}}==
<syntaxhighlight lang="scheme">#lang transd
 
MainModule: {
_start: (λ
(with s "She was a soul stripper. She took my heart!"
(textout (replace s "(a|e|i)" "")))
)
}</syntaxhighlight>
{{out}}
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|True BASIC}}==
<syntaxhighlight lang="qbasic">FUNCTION stripchars$(text$, remove$)
LET s$ = text$
FOR i = 1 TO LEN(remove$)
DO
LET t = POS(s$, (remove$)[i:i])
IF t <> 0 THEN LET s$ = (s$)[1:t-1] & (s$)[t+1:maxnum] ELSE EXIT DO
LOOP
NEXT i
LET stripchars$ = s$
END FUNCTION
 
PRINT stripchars$("She was a soul stripper. She took my heart!", "aei")
END</syntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT,{}
string="She was a soul stripper. She took my heart!"
Line 2,390 ⟶ 2,875:
print string
print stringstrip
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,405 ⟶ 2,890:
Since the partial argument list (the arguments belonging to the TXR script) is a suffix of the full argument list (the complete arguments which include the invoking command and the script name), the classic Lisp function <code>ldiff</code> comes in handy in obtaining just the prefix, for printing the usage:
<langsyntaxhighlight lang="txrlisp">(defun strip-chars (str set)
(let* ((regex-ast ^(set ,*(list-str set)))
(regex-obj (regex-compile regex-ast)))
Line 2,417 ⟶ 2,902:
((str set extra) (usage))
((str set . junk) (pprinl (strip-chars str set)))
(else (usage)))</langsyntaxhighlight>
{{out}}
<pre>$ txr strip-chars-2.tl
Line 2,426 ⟶ 2,911:
Now here is a rewrite of <code>strip-chars</code> which just uses classic Lisp that has been generalized to work over strings, plus the <code>do</code> syntax (a sibling of the <code>op</code> operator) that provides syntactic sugar for a lambda function whose body is an operator or macro form.
 
<langsyntaxhighlight lang="txr">(defun strip-chars (str set)
(mappend (do if (memq @1 set) (list @1)) str))</langsyntaxhighlight>
 
<code>(do if (memq @1 set) (list @1))</code> is just <code>(lambda (item) (if (memq item set) (list item)))</code>.
Line 2,435 ⟶ 2,920:
One would normally do this using the standard tr(1) command:
{{works with|sh}}
<langsyntaxhighlight lang="bash">strip_chars() {
echo "$1" | tr -d "$2"
}</langsyntaxhighlight>
But it can also be accomplished with bash's built-in parameter expansions:
{{works with|bash}}
<langsyntaxhighlight lang="bash">function strip_chars {
echo "${1//[$2]}"
}</langsyntaxhighlight>
Test code:
<langsyntaxhighlight lang="bash"> strip_chars "She was a soul stripper. She took my heart!" aei</langsyntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 2,450 ⟶ 2,935:
=={{header|Ursala}}==
Normally there's no need to define this operation because it's built in.
<langsyntaxhighlight Ursalalang="ursala">strip = ~&j
 
#cast %s
 
test = strip('she was a soul stripper. she took my heart','aei')</langsyntaxhighlight>
{{out}}
<pre>
Line 2,466 ⟶ 2,951:
Pass the optional bSpace parameter True to replace stripped characters with spaces, otherwise replaced with null.
 
<langsyntaxhighlight lang="vb">Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean)
Dim i As Integer, stReplace As String
If bSpace = True Then
Line 2,477 ⟶ 2,962:
Next i
StripChars = stString
End Function</langsyntaxhighlight>
 
{{out}}
Line 2,487 ⟶ 2,972:
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function stripchars(s1,s2)
For i = 1 To Len(s1)
Line 2,498 ⟶ 2,983:
 
WScript.StdOut.Write stripchars("She was a soul stripper. She took my heart!","aei")
</syntaxhighlight>
</lang>
 
{{Out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
println(stripchars("She was a soul stripper. She took my heart!","aei"))
}
 
fn stripchars(str string, charstrip string) string {
mut newstr := str
for element in charstrip {newstr = newstr.replace(element.ascii_str(), '')}
return newstr
}</syntaxhighlight>
 
{{out}}
<pre>
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Wren}}==
<langsyntaxhighlight javascriptlang="wren">var stripChars = Fn.new { |s, t|
return s.map { |c|
return (t.indexOf(c) == -1) ? c : ""
Line 2,510 ⟶ 3,011:
}
 
System.print(stripChars.call("She was a soul stripper. She took my heart!", "aei"))</langsyntaxhighlight>
 
{{out}}
Line 2,518 ⟶ 3,019:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \make strings zero-terminated
 
func In(Char, Chars); \Is Char in the string Chars?
Line 2,539 ⟶ 3,040:
];
 
Text(0, StripChars("She was a soul stripper. She took my heart!", "aei"))</langsyntaxhighlight>
 
Output:
Line 2,545 ⟶ 3,046:
Sh ws soul strppr. Sh took my hrt!
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">sub stripchars$(text$, remove$)
local i, t, s$
s$ = text$
for i = 1 to len(remove$)
do
t = instr(s$, mid$(remove$, i, 1))
if t then s$ = left$(s$, t - 1) + mid$(s$, t + 1) else break : fi
loop
next i
return s$
end sub
 
print stripchars$("She was a soul stripper. She took my heart!", "aei")</syntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">println("She was a soul stripper. She took my heart!" - "aei")
//-->Sh ws soul strppr. Sh took my hrt!</langsyntaxhighlight>
44

edits