// MARK: - 扩展String下标方法
extension String
{
/// 根据开始位置和长度截取字符串,索引从0开始
func subString(start: Int, length: Int = -1) -> String
{
var len = length
if len == -1
{
len = self.count - start
}
let st = self.index(startIndex, offsetBy: start)
let en = self.index(st, offsetBy: len)
return String(self[st ..< en])
}
}
转自:航歌