gpt4 book ai didi

swift:如何删除特定字符?

转载 作者:搜寻专家 更新时间:2023-10-30 22:21:35 26 4
gpt4 key购买 nike

之类的字符串! !!耶! ! ,我想删除 !,当我这样编码时

for index in InputName.characters.indices {
if String(InputName[index]) == "" || InputName.substringToIndex(index) == "!" {
InputName.removeAtIndex(index)
}
}

出现“fatal error: subscript: subRange extends past String end”错误,我该怎么办?谢谢:D

最佳答案

swift 5+

let myString = "aaaaaaaabbbb"
let replaced = myString.replacingOccurrences(of: "bbbb", with: "") // "aaaaaaaa"

关于swift:如何删除特定字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39187159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com