Created
October 11, 2019 21:27
-
-
Save Lucien/2e622d9a15ef0b04b35d035e76e9c99d to your computer and use it in GitHub Desktop.
Substring from NSRange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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