Skip to content

Instantly share code, notes, and snippets.

@dfelber
Created October 17, 2016 11:51
Show Gist options
  • Save dfelber/45544c93e90e371acca1a03ee9373861 to your computer and use it in GitHub Desktop.
Save dfelber/45544c93e90e371acca1a03ee9373861 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 {
let start = startIndex.advancedBy(r.startIndex)
let end = start.advancedBy(r.endIndex - r.startIndex)
return self[Range(start ..< end)]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment