【问题标题】:In Swift, is the count of an instance of String.CharacterView always equal to the distance between the startIndex and endIndex in all cases?在 Swift 中,String.CharacterView 实例的计数是否总是等于 startIndex 和 endIndex 之间的距离?
【发布时间】:2016-10-04 15:07:12
【问题描述】:

标题说明了一切。在 Swift 中,String.CharacterView 实例的计数是否总是等于 startIndex 和 endIndex 之间的距离?

Swift 2.3:

string.characters.count == string.characters.startIndex.distanceTo(string.characters.endIndex)

斯威夫特 3:

string.characters.count == string.characters.distance(from:string.characters.startIndex, to:string.characters.endIndex)

【问题讨论】:

    标签: swift string indexof


    【解决方案1】:

    是的。这是Collection 的要求。从startIndexendIndex 的迭代必须完全覆盖所有元素。将采取的步数(距离)必须等于count,否则您将违反该要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 2016-12-24
      相关资源
      最近更新 更多