Original blog, reproduced please indicate the source
Blog.csdn.net/hello_hwc
Previously wrote a swift string foundation, want to understand the classmate can look down.
http://blog.csdn.net/hello_hwc/article/details/39853023
Replace
To replace with A/
var"http://blog.csdn.net/hello_hwc?viewmode=list"var filtered = url.stringByReplacingOccurrencesOfString("?""/"rangenil)
Results
"http://blog.csdn.net/hello_hwc/viewmode=list"
Filter
Filter out individual characters/
var"http://blog.csdn.net/hello_hwc?viewmode=list"var filtered = url.stringByReplacingOccurrencesOfString("/"""rangenil)
Results
"http:blog.csdn.nethello_hwc?viewmode=list"
Filter out the opening and closing blanks
var" http://blog.csdn.net/hello_hwc?viewmode=list "var newString = url.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
Results
"http://blog.csdn.net/hello_hwc?viewmode=list"
Cutting
Use/as delimiter for string to cut, no empty string allowed
Using the Split function
"http://blog.csdn.net/hello_hwc?viewmode=list"let splitedarray = split(url){$0"/"}
The result is an array
"http:""blog.csdn.net""hello_hwc?viewmode=list"
Use/as delimiter for string to cut, allow empty string
var"http://blog.csdn.net/hello_hwc?viewmode=list"let arrayresult = split(url, maxSplit:url.lengthOfBytesUsingEncoding(NSUTF8StringEncoding), allowEmptySlices: true) { (char:Character) ->in return"/"}
Results
"http:""""blog.csdn.net""hello_hwc?viewmode=list"
Stitching
let splitedarray = ["1","2","3"]letjoin("/", splitedarray)
Results
"1/2/3"
Swift string replacement/filtering/cutting/splicing