Created
October 26, 2019 13:36
-
-
Save mjhassan/f4d72d3de148271161489799d60dc753 to your computer and use it in GitHub Desktop.
String sclicing make easy
This file contains hidden or 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 { | |
| public subscript (range: PartialRangeFrom<Int>) -> Substring { | |
| return self[index(startIndex, offsetBy: range.lowerBound)..<endIndex] | |
| } | |
| public subscript (range: PartialRangeUpTo<Int>) -> Substring { | |
| return self[startIndex..<index(endIndex, offsetBy: range.upperBound)] | |
| } | |
| public subscript (range: PartialRangeThrough<Int>) -> Substring { | |
| return self[startIndex...index(endIndex, offsetBy: range.upperBound)] | |
| } | |
| public subscript (range: ClosedRange<Int>) -> Substring { | |
| return self[index(startIndex, offsetBy: range.lowerBound)...index(startIndex, offsetBy: range.upperBound)] | |
| } | |
| public subscript (range: Range<Int>) -> Substring { | |
| return self[index(startIndex, offsetBy: range.lowerBound)..<index(startIndex, offsetBy: range.upperBound)] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment