let urlString = "www.hhhit.com"
//不 转换成 NSString 的写法, 需要定义 index
let index = urlString.index(urlString.startIndex, offsetBy: 3)
let header = urlString.substring(to: index)
print(header)
[推荐] 转换
//将 String 类型转换成 NSString 类型 再进行截取比较方便
let head = (urlString as NSString).substring(to: 4)
print(head)//www
let middle = (urlString as NSString).substring(with: NSMakeRange(4, 5))
print(middle)//hhhit
let footer = (urlString as NSString).substring(from: 10)
print(footer)//com
其他可参考文章 : http://blog.csdn.net/aa31140105/article/details/76367602