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)
Use an extension on string e.g. stackoverflow.com/a/24144365/1032372
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With