I have to say that for a "modern" language Swift certainly makes a meal of specifying a range to capture a substring.
My question: Is there a way to create a <String.Index>
using Range(0...4)
or indeed 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)