【发布时间】:2017-03-08 09:11:11
【问题描述】:
假设有一个字符串“johngoestoschool”,它应该变成“JoHnGoEsToScHoOl”,如果中间有特殊字符,它应该忽略它,例如给定字符串“jo$%@#hn^goe!st#os&choo)l”答案应该是“Jo$%@#Hn^GoE!sT#oS&cHoO)l”
来自this的回答,我们为了迭代我们可以这样做:
let s = "alpha"
for i in s.characters.indices[s.startIndex..<s.endIndex]
{
print(s[i])
}
为什么我们不能在这里打印“i”的值? 当我们执行 i.customPlaygroundQuickLook 时,它会键入 int 0 到 int4。
所以我的想法是
if (i.customPlaygroundQuickLook == 3) {
s.characters.currentindex = capitalized
}
请帮忙
【问题讨论】:
标签: ios arrays string swift3 swift-playground