<分区>
您好,我正在尝试操作一个字符串,尽管来自 Apple 开发人员网站的代码不起作用:
let name = "Marie Curie"
let firstSpace = name.firstIndex(of: " ") ?? name.endIndex
let firstName = name[..<firstSpace]
// firstName == "Marie"
您可以在此处找到示例:https://developer.apple.com/documentation/swift/string
似乎 firstIndex(of: "")
不再存在
我不明白为什么这不起作用是否有一个具有不同名称的新函数或者可能是什么问题?我很困惑,苹果是不是错过了这个,到目前为止还没有人需要它???
非常感谢
虽然我正在寻找类似 index(of: String) 的东西,但它用 index(of: Character) 回答了一个类似的问题