数组删除对象:?字符串可以不与“INT”被索引,它具有可变大小要素误差
问题描述:
你好我想从阵列中迅速3除去对象给我错误数组删除对象:?字符串可以不与“INT”被索引,它具有可变大小要素误差
串可以不与“INT”被索引,它具有可变大小的元素错误
我这里
var itemListcomming = String()
itemListcomming = itemListcomming.remove(at: 16)
代码什么想法?
感谢
答
在斯威夫特2 String
是一个小的痛苦,当谈到索引的工作,更是让斯威夫特3.你不能给一个Int
为指标,但操纵startIndex
/endIndex
到达到你想要的位置。从Swift 1.0开始就是这样的。
总之,如果你想删除该字符串的第16个字符:
var itemListcomming = "Lorem ipsum dolor sit amet"
let index = itemListcomming.index(itemListcomming.startIndex, offsetBy: 16)
itemListcomming.remove(at: index)
print(itemListcomming)
谢谢!工作我认为会帮助很多人! – SwiftDeveloper
你会介意分享这方面的详细资料吗? @CodeDifferent –