var str = "12345678"
let length = str.characters.count
//截取前四位
var sub1 = str.substring(to: str.index(str.startIndex, offsetBy:4))//截取后2位(两种方法)
var sub2 = str.substring(from: str.index(str.startIndex, offsetBy: length-2))
var sub3 = str.substring(from: str.index(str.endIndex, offsetBy: -2))//截取中间4位,从第2位开始(二种方法)
let start1 = str.index(str.startIndex, offsetBy:2)
str = str.substring(from: start1)//取到从第2位开始的所有字符
let end1 = str.index(str.startIndex, offsetBy:4)
var sub5 = str.substring(to: end1)//从新的字符开始取4位