To remove a substring at a specified range, use the removeRange(_:) method:
1 let range = advance(welcome.endIndex, -6)..<welcome.endIndex 2 welcome.removeRange(range) 3 println(welcome) 4 // prints "hello"
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/ca/jEUH0.l
Hi there,
I don't fully understand the syntax and the function of line 1 in the code above.
Please explain using this string:
let welcome = "hello there"
This is what I've worked out:
"To change the start and end index, use
advance()
."
From: https://stackoverflow.com/a/24045156/4839671
A better documentation of advance()
is welcomed. i.e. it's arguments
Use
..<
to make a range that omits its upper valueExcerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/ca/jEUH0.l
welcome.endIndex
will be 11