For example, I have the following string:
e it z should a make q sense
and I want it to be:
it should make sense
Is there a single way to do this without having to create or loop through some character set?
For example, I have the following string:
e it z should a make q sense
and I want it to be:
it should make sense
Is there a single way to do this without having to create or loop through some character set?
You can use a regex to achieve your goals.
let stringWithSingleChars = "e it z should a make q sense"
stringWithSingleChars.replacingOccurrences(of: #"\b\w\b"#, with: "", options: .regularExpression, range: nil)
The pattern matches a word boundary, then a single word character, then a whitespace, resulting in all single-characters followed by a space being matched.