How to resolve the algorithm Strip a set of characters from a string step by step in the Swift 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 Swift 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 Swift programming language
Source code in the swift programming language
extension String {
func stripCharactersInSet(chars: [Character]) -> String {
return String(seq: filter(self) {find(chars, $0) == nil})
}
}
let aString = "She was a soul stripper. She took my heart!"
let chars: [Character] = ["a", "e", "i"]
println(aString.stripCharactersInSet(chars))
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the R programming language
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the Lua programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the Lua programming language
You may also check:How to resolve the algorithm LU decomposition step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the PostScript programming language