Avant d'utiliser replaceOccurrences (of: with :) Si vous créez un dictionnaire, vous pouvez "remplacer plusieurs chaînes de caractères".
var str = "ABCDEF"
var newStr: String {
let dictionary = ["A": "1","B": "2","C": "3","D": "4","E": "5","F": "6"]
return dictionary.reduce(str) { $0.replacingOccurrences(of: $1.key, with: $1.value) }
}
print(newStr) // 123456
Recommended Posts