字符串分割函数:
let str: String = "http://www.example.com/img/string.jpg"
imgback( str )
imgpath( str )
func imgback(str: String ) -> String {
var imgname: NSString = str. lastPathComponent
var point = imgname. rangeOfString ( "." ). location
return imgname. substringFromIndex (point)
}
func imgpath(str: String ) -> String {
var imgname: NSString = str. lastPathComponent
return str. substringToIndex ( advance (str. startIndex , countElements (str)-imgname. length ))
}
字符串转数组:
var tagstr = "#aaa#bbb#ccc#ddd#eee#fff# 搞笑 # 体育 # 娱乐 #"
var tagarr = tagstr . componentsSeparatedByString ( "#" )
for (index,element) in enumerate ( tagarr ) {
" \(index) - \(element) "
}
let str: String = "http://www.example.com/img/string.jpg"
imgback( str )
imgpath( str )
func imgback(str: String ) -> String {
var imgname: NSString = str. lastPathComponent
var point = imgname. rangeOfString ( "." ). location
return imgname. substringFromIndex (point)
}
func imgpath(str: String ) -> String {
var imgname: NSString = str. lastPathComponent
return str. substringToIndex ( advance (str. startIndex , countElements (str)-imgname. length ))
}
字符串转数组:
var tagstr = "#aaa#bbb#ccc#ddd#eee#fff# 搞笑 # 体育 # 娱乐 #"
var tagarr = tagstr . componentsSeparatedByString ( "#" )
for (index,element) in enumerate ( tagarr ) {
" \(index) - \(element) "
}