let greeting = "Guten Tag!"
greeting[greeting.startIndex.successor()]
// "u"
greeting[greeting.startIndex.successor().successor().successor()]
// "e"
有没有其他选择,而不是多次写.successor()
?
答案 0 :(得分:1)
在 Swift 2.0 中,这是advancedBy
:
greeting[greeting.startIndex.advancedBy(3)] // "e"
在 Swift 1.2 :
greeting[advance(greeting.startIndex, 3)] // "e"