Created
January 23, 2015 05:26
-
-
Save ericcgu/c1507162b97c4534f0c7 to your computer and use it in GitHub Desktop.
String Range Extension
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 { | |
subscript (i: Int) -> Character { | |
return self[advance(self.startIndex, i)] | |
} | |
subscript (i: Int) -> String { | |
return String(self[i] as Character) | |
} | |
subscript (r: Range<Int>) -> String { | |
return substringWithRange(Range(start: advance(startIndex, r.startIndex), end: advance(startIndex, r.endIndex))) | |
} | |
} | |
"abcde"[0] === "a" | |
"abcde"[0...2] === "abc" | |
"abcde"[2..<4] === "cd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment