Ori*_*rds 9 substring range swift
所以我有这个快速的代码:
func didReceiveResponse(response:String) {
...
let substr = response[11...]
Run Code Online (Sandbox Code Playgroud)
根据我的解释,substr应该是一个子串,引用响应字符串中索引11之后的所有字符.
实际发生的是这个编译器错误:
Cannot subscript a value of type 'String' with an index of type 'CountablePartialRangeFrom<Int>'
这似乎应该是显而易见的,有人可以帮忙吗?
哎呦.似乎我需要这样做:
let idx = response.index(response.startIndex, offsetBy: 11)
let substr = response[idx...]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6554 次 |
| 最近记录: |