美文网首页
'substring(from:)' is de

'substring(from:)' is de

作者: 匿名的他 | 来源:发表于2017-10-24 15:44 被阅读25次
'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.

swift4更新了字符串操作的API方法 特此记录一波
substring方法被标记为过时。。其实还不怎么会用呢就。。

let urlStr = "tel://114"
if let rangeIndex = urlStr.range(of: "tel://") {
      let number = urlStr[rangeIndex.upperBound...] //substring(from: rangeIndex.upperBound)
      print("number is :\(number)")
}

可以看到字符串urlStr被当做字符数组来处理 但是直接通过下标来获取是不行的 如下:


481508830941_.pic.jpg

必须是CountablePartialRangeFrom<Int>这种类型的下标,以后有空再研究:)

相关文章

网友评论

      本文标题:'substring(from:)' is de

      本文链接:https://www.haomeiwen.com/subject/dutxpxtx.html