本以为没其他方法了。不过还是带着试一试的态度,在英文板块发了个求助帖,别人回复说用对象。一测试竟然 0 秒就完成了!这个方法太有用了,特意在这里发个帖子让更多人知道
测试代码:
Code: Select all
SetBatchLines -1
; 生成 10 万个数字
Loop, 100000
fullList .= "," A_Index
fullList := Trim(fullList, ",")
; 生成 6 万个数字
Loop, 60000
subList .= "," A_Index
subList := Trim(subList, ",")
; 获取 4 万个反集数字
; 方法一: InStr()
TickCount_Start := A_TickCount ; 计时开始
resultList := ""
Loop, Parse, fullList, CSV
If !InStr(subList, A_LoopField)
resultList .= "," A_LoopField
MsgBox, % "耗时: " (A_TickCount-TickCount_Start)/1000 " 秒" ; 我这里显示“耗时: 38.516000 秒”
; 方法二: Object
TickCount_Start := A_TickCount ; 计时开始
; 把 6 万个数字列表转为对象
oSubList := {}
Loop, Parse, subList, CSV
oSubList[A_LoopField] := 1
; 开始...
resultList := ""
Loop, Parse, fullList, CSV
If !oSubList[A_LoopField]
resultList .= "," A_LoopField
MsgBox, % "耗时: " (A_TickCount-TickCount_Start)/1000 " 秒" ; 我这里显示“耗时: 0.125000 秒”