Last active
August 29, 2015 14:02
-
-
Save exPHAT/5505bbd094300538e6b0 to your computer and use it in GitHub Desktop.
A simple subscript to allow python-like string slicing.
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
// Example: mystring[0] or mystring[2,6] | |
import Cocoa | |
extension String { | |
subscript(index:Int) -> Character { | |
get { | |
return Character(bridgeToObjectiveC().substringWithRange(NSMakeRange(index,1))) | |
} | |
} | |
subscript(start:Int, end:Int) -> String { | |
get { | |
return String(bridgeToObjectiveC().substringWithRange(NSMakeRange(start, end-start))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment