我有字符串 "Das Auto ist blau, das andere ist allerdings blau"
我试图只用 "blau"
替换第一个 "red"
。
我已经用 .replacingOccurrences
试过了,但这对我不起作用。
答案 0 :(得分:0)
你可以试试
let str = "Das Auto ist blau, das andere ist allerdings blau"
if let range = str.range(of:"blau") {
print(str.replacingCharacters(in: range, with:"red"))
}