gpt4 book ai didi

swift - swift 中 .successor() 的替代品?

转载 作者:行者123 更新时间:2023-11-30 10:11:37 25 4
gpt4 key购买 nike

let greeting = "Guten Tag!"

greeting[greeting.startIndex.successor()]
// "u"

greeting[greeting.startIndex.successor().successor().successor()]
// "e"

除了多次编写 .successor() 之外,还有其他选择吗?

最佳答案

Swift 2.0中,这是advancedBy:

greeting[greeting.startIndex.advancedBy(3)]  // "e"

Swift 1.2中:

greeting[advance(greeting.startIndex, 3)]  // "e"

关于swift - swift 中 .successor() 的替代品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32680079/

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