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]")`
Not a robot (talk | contribs) (Add Refal) |
(→{{header|Kotlin}}: Corrected Kotlin solution: the use of regex is error-prone, e.g. `stripChars("fails to remove ] bracket", "aei]")`) |
||
(3 intermediate revisions by 3 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
{{out}}
<pre>Sh ws soul strppr. Sh took my hrt!</pre>
Line 1,454 ⟶ 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,864 ⟶ 1,875:
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">
fun main(args: Array<String>) {
Line 2,780 ⟶ 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}}==
|