Range (0 ... 4) and substringWithRange?
I have to say that for a "modern" language, Swift is of course cooking up a range for capturing a substring.
My question is: Is there a way to create <String.Index>
with, Range(0...4)
or really a way to cast the result (of type <Int>
) so that it can be used with substringWithRange
?
let myString = "HappyDays"
var rangeString = Range(start: advance(myString.startIndex, 5), end: advance(myString.endIndex, -1))
myString.substringWithRange(rangeString) // >>> "Day"
...
// Can this be used to generate a range for substringWithRange?
var hardRange = Range(0...4)
+3
source to share