Skip to content

Instantly share code, notes, and snippets.

@jaminguy
Created October 10, 2015 03:43
Show Gist options
  • Save jaminguy/9d331f09b659d6fbe838 to your computer and use it in GitHub Desktop.
Save jaminguy/9d331f09b659d6fbe838 to your computer and use it in GitHub Desktop.
extension String {
subscript (i: Int) -> Character {
return self[self.startIndex.advancedBy(i)]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
}
subscript (r: Range<Int>) -> String {
return substringWithRange(Range(start: startIndex.advancedBy(r.startIndex), end: startIndex.advancedBy(r.endIndex)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment