首页 > 编程语言 > 详细

swift 4 字符串截取

时间:2018-06-07 12:40:39      阅读:257      评论:0      收藏:0      [点我收藏+]

截取某字符串的前10个字符串

let sub1 = str.prefix(10)

截取某字符串的后10个字符串

let str1 = str.suffix(10)

也可以换种写法

let index2 = str.index(str.endIndex, offsetBy: -10)
let sub4 = str[index2..<str.endIndex]

截取某字符串的第3个字符到第6个字符范围的字符串

let index3 = str.index(str.startIndex, offsetBy: 3)
let index4 = str.index(str.startIndex, offsetBy: 6)
let sub4 = str[index3..<index4]

 

swift 4 字符串截取

原文:https://www.cnblogs.com/heyode/p/9149483.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!