- Dim srcFile, dstFile,sSecond
- srcFile = "1.txt" '源文件
- dstFile = "2.txt" '目标文件
- sSecond = 19.5 '增加秒数为正,减少秒数为负
- Dim fso, objFile
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set objFile = fso.OpenTextFile(srcFile, 1)
- Dim reg
- Set reg = New RegExp
- reg.Pattern = "^\[([0-5][0-9]):([0-5][0-9]\.[0-9][0-9])\](.*)$"
- Dim n
- n = 0
- ReDim arr(n)
- Do Until objFile.AtEndOfStream
- Dim str, match
- ReDim PreServe arr(n)
- str = objFile.ReadLine
- Set match = reg.Execute(str)
- If match.Count > 0 Then
- Dim t, mm, ss, cs
- t = 6000 * match(0).SubMatches(0) + 100 * (sSecond + match(0).SubMatches(1))
- mm = Mid(Fix(t / 6000) + 100, 2)
- ss = Mid(t Mod 6000 + 10000, 2, 2)
- cs = Mid(t Mod 6000 + 10000, 4)
- str = "[" & mm & ":" & ss & "." & cs & "]" & match(0).SubMatches(2)
- End If
- arr(n) = str
- n = n + 1
- Loop
- fso.OpenTextFile(dstFile, 2, True).Write Join(arr, vbCrLf)
- MsgBox "Done"
复制代码 |