我有一个动态切片数组,我想将它们分成两个,例如:
["21:35 DXB", "23:40 HBE"]<br/>
["14:30 DXB", "16:35 HBE"]<br/>
["04:10 HBE", "09:10 DXB"]<br/>
["01:45 HBE", "06:50 DXB"]<br/>
["11:10 HBE", "16:15 DXB"]<br/>
["18:25 HBE", "23:35 DXB"]
我想要从DXB到HBE的第一个数组:
["21:35 DXB", "23:40 HBE"]<br/>
["14:30 DXB", "16:35 HBE"]<br/>
从HBE到DXB的第二个数组:
["04:10 HBE", "09:10 DXB"]<br/>
["01:45 HBE", "06:50 DXB"]<br/>
["11:10 HBE", "16:15 DXB"]<br/>
["18:25 HBE", "23:35 DXB"]
答案 0 :(得分:1)
您可以遍历数组,然后将它们添加到不同的数组中:
let arr = [["21:35 DXB", "23:40 HBE"], ["14:30 DXB", "16:35 HBE"],["04:10 HBE", "09:10 DXB"],["01:45 HBE", "06:50 DXB"], ["11:10 HBE", "16:15 DXB"], ["18:25 HBE", "23:35 DXB"]]
var arrDXB = [[String]]()
var arrHBE = [[String]]()
for item in arr{
if item[0].rangeOfString("DXB") != nil {
arrDXB.append(item)
}
else{
arrHBE.append(item)
}
}
arrDXB
将是[["21:35 DXB", "23:40 HBE"], ["14:30 DXB", "16:35 HBE"]]
arrHBE
将为[["04:10 HBE", "09:10 DXB"], ["01:45 HBE", "06:50 DXB"], ["11:10 HBE", "16:15 DXB"], ["18:25 HBE", "23:35 DXB"]]