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]")`
m (→‎{{header|Wren}}: Changed to Wren S/H)
(→‎{{header|Kotlin}}: Corrected Kotlin solution: the use of regex is error-prone, e.g. `stripChars("fails to remove ] bracket", "aei]")`)
 
(6 intermediate revisions by 4 users not shown)
Line 205:
{{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
 
printfn "%s" (stripCharsWRITE "She was a soul stripper. She took my heart!" stripchars "aei")/</syntaxhighlight>
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
Line 1,285 ⟶ 1,296:
=={{header|EasyLang}}==
 
<syntaxhighlight lang=easylang>
func$ strip s$ del$ .
delfor c$[] =in strchars dels$
if strpos ifdel$ c$ =<> d$0
i = 1
c$ = ""
repeat
c$ = substr s$ i 1
until c$ = ""
for d$ in del$[]
if c$ = d$
c$ = ""
.
.
r$ &= c$
i += 1
.
return r$
Line 1,461 ⟶ 1,465:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">let stripChars text (chars:string) =
let stripChars text (chars:string) =
ArraySeq.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")
 
0</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</syntaxhighlight>
</pre>
Output
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
 
=={{header|Factor}}==
Line 1,871 ⟶ 1,875:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">//fun versionstripChars(s: 1String, r: String) = s.0.6filter { it !in r }
 
fun stripChars(s: String, r: String) = s.replace(Regex("[$r]"), "")
 
fun main(args: Array<String>) {
Line 2,416 ⟶ 2,418:
stripchars: func [str chars] [trim/with str chars]
stripchars "She was a soul stripper. She took my heart!" "aei"</syntaxhighlight>
 
=={{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}}==
Line 2,681 ⟶ 2,696:
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}}==
Line 2,763 ⟶ 2,789:
<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}}==
44

edits