一,最常用的方法substringFromIndex,substringToIndexsubstringWithRange
var s="1234567890"
var ns1=(s as NSString).substringFromIndex(5)
ns2=(s ).substringToIndex(4)
ns3=(s ).substringWithRange(NSMakeRange(,1)) println(ns1)//67890(ns2)//1234(ns3)//5
"1234567890"
let index = advance(s.startIndex,5)
index2 = (s.endIndex,-6);
range = Range<String.Index>(start: index2,end: index)
s1:=s.substringFromIndex(index)
s2:=s.substringToIndex(index2)
s3=s.substringWithRange(range)
println(s1)//67890 (s2)//1234(s3)//5
原文链接:https://www.f2er.com/swift/327098.html