如果您的样本数据具有代表性,请使用分组正则表达式:
Dim sAll : sAll = goFS.OpenTextFile("..\data\17050037.txt").ReadAll
Dim rePair : Set rePair = New RegExp
rePair.Global = True
rePair.Multiline = True
rePair.Pattern = "^(\d+)\r\n^(\d+)\r\n"
Dim oMTS : Set oMTS = rePair.Execute(sAll)
Dim oMt
For Each oMT IN oMTS
WScript.Echo "{"
WScript.Echo oMT.SubMatches(0) & ","
WScript.Echo oMT.SubMatches(1)
WScript.Echo "}"
Next
输出:
{
11111,
22222
}
{
33333,
44444
}
{
55555,
66666
}
{
77777,
88888
}
添加:
如果您更喜欢线路循环,请尝试:
Dim file : Set file = goFS.OpenTextFile("..\data\17050037.txt")
Dim state : state = 0
Do Until file.AtEndOfStream
Dim Line : Line = file.ReadLine
Select Case state
Case 1, 3
WScript.Echo "{"
WScript.Echo Line & ","
state = state + 1
Case 2, 4
WScript.Echo Line
WScript.Echo "}"
state = state + 1
Case Else
If "0x" = Left(Line, 2) Then state = 1
End Select
Loop
file.Close