Created
December 22, 2014 08:16
-
-
Save Harryyan/4eda1276e096d93e4345 to your computer and use it in GitHub Desktop.
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(subrange: Range<Int>) -> String { | |
get { | |
var start = advance(startIndex, subrange.startIndex) | |
var end = advance(startIndex, subrange.endIndex) | |
return substringWithRange(Range(start: start, end: end)) | |
} | |
set { | |
var start = advance(startIndex, subrange.startIndex) | |
var end = advance(startIndex, subrange.endIndex) | |
var updateRange = Range(start: start, end: end) | |
self.replaceRange(updateRange, with: newValue) | |
} | |
} | |
subscript(index:Int) -> String { | |
get{ | |
return self[Range(start: index, end: index+1)] | |
} | |
set{ | |
self[Range(start:index,end:index+1)]=newValue; | |
} | |
} | |
subscript(start:Int,length:Int)->String{ | |
get{ | |
return self[Range(start:start,end:start+length+1)] | |
} | |
set{ | |
self[Range(start:start,end:start+length+1)]=newValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment