How to resolve the algorithm Strip a set of characters from a string step by step in the Elixir programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Strip a set of characters from a string step by step in the Elixir programming language
Table of Contents
Problem Statement
Create a function that strips a set of characters from a string.
The function should take two arguments:
The returned string should contain the first string, stripped of any characters in the second argument:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Strip a set of characters from a string step by step in the Elixir programming language
Source code in the elixir programming language
str = "She was a soul stripper. She took my heart!"
String.replace(str, ~r/[aei]/, "")
# => Sh ws soul strppr. Sh took my hrt!
defmodule RC do
def stripchars(str, chars) do
String.replace(str, ~r/[#{chars}]/, "")
end
end
str = "She was a soul stripper. She took my heart!"
RC.stripchars(str, "aei")
# => Sh ws soul strppr. Sh took my hrt!
You may also check:How to resolve the algorithm String append step by step in the C# programming language
You may also check:How to resolve the algorithm Tau function step by step in the Quackery programming language
You may also check:How to resolve the algorithm Enumerations step by step in the VBA programming language
You may also check:How to resolve the algorithm Move-to-front algorithm step by step in the Java programming language
You may also check:How to resolve the algorithm Parsing/RPN to infix conversion step by step in the C++ programming language