Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Lucien
Created October 11, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lucien/2e622d9a15ef0b04b35d035e76e9c99d to your computer and use it in GitHub Desktop.
Save Lucien/2e622d9a15ef0b04b35d035e76e9c99d to your computer and use it in GitHub Desktop.
Substring from NSRange
extension String {
func substring(range: NSRange) -> String {
let location = range.lowerBound
let lenght = range.upperBound
let start = index(startIndex, offsetBy: location)
let end = index(start, offsetBy: length - location)
return String(self[start ..< end])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment