3 ms·
I'd do s = str.replacing(" ", with: " ") which seems to go along well with the "sorted" and "appending" mentioned in the new API design guidelines: https
by comex 11y ago
I'd do
s = str.replacing(" ", with: " ")
which seems to go along well with the "sorted" and "appending" mentioned in the new API design guidelines:
https://swift.org/documentation/api-design-guidelines/#be-grammatical https://swift.org/documentation/api-design-guidelines/#be-gr...
This is a bit more verbose if you need to chain a lot of replacements... but chances are you shouldn't be doing that in the first place! Instead there should be a version that takes a dictionary, like
str.replacing(["<": "<", "&": "&"])
This is better because most of the time you don't actually want characters produced by earlier replacements to match later ones, and it can be faster for large strings.