import UIKit
class ViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//将字符串切割成数组
var nameString = NSString(string:"吉姆,杰克,哈利,史泰龙,迈克")
var nameArray:NSArray = nameString.componentsSeparatedByString(",")as NSArray
for i in 0...nameArray.count - 1{
//获取切割后的字符串名字
var name:String = nameArray.objectAtIndex(i)as! String
println(name)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
///:打印结果
吉姆
杰克
哈利
史泰龙
迈克
网友评论