Strip a set of characters from a string: Difference between revisions
Strip a set of characters from a string (view source)
Revision as of 16:27, 5 April 2024
, 1 month ago→{{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
IF c not.in chs: PUT result^c IN result
RETURN result
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 1,285 ⟶ 1,296:
=={{header|EasyLang}}==
<syntaxhighlight
func$ strip s$ del$ .
▲ if c$ = d$
▲ c$ = ""
▲ .
.
r$ &= c$
.
return r$
Line 1,461 ⟶ 1,465:
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
let stripChars text (chars:string) =
fun (s:string) c -> s.Replace(c.ToString(),"")
) text
printfn "%s" (stripChars "She was a soul stripper. She took my heart!" "aei")
{{out}}
<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>
▲<pre>Sh ws soul strppr. Sh took my hrt!</pre>
=={{header|Factor}}==
Line 1,871 ⟶ 1,875:
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">
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}}==
|