Last active
April 21, 2016 07:41
-
-
Save dragouf/e8f30a3fdecbee0af046 to your computer and use it in GitHub Desktop.
swift String extension
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 | |
{ | |
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