【发布时间】:2019-09-25 03:37:40
【问题描述】:
我想得到一个子字符串到某个索引
let index = n % s.count
let remainderOfS = s.substring(from: index)
但它不允许索引,因为它是 Int 而不是 String.Index。所以我试试
let index = n % s.count
let strIndex = s.formIndex(s.startIndex, offsetBy: index)
let remainderOfS = s.substring(from: strIndex)
但现在抱怨:无法使用类型为“(String.Index,offsetBy:Int)”的参数列表调用“formIndex”,需要类型为“(inout Self.Index,offsetBy:Int)”的参数列表,即使这是我在其他人问这个问题的地方找到的解决方案。我错过了什么?
编辑:这也不起作用
let remainderOfS = String(s[..<index])
引用:'subscript(_:)' 已在此处明确标记为不可用 (Swift.String)
【问题讨论】:
-
@Tommy:你在哪里找到了那个解决方案?