返回列表 发帖
本帖最后由 WHY 于 2015-11-8 17:26 编辑

假设Z轴数据范围:-9999~9999
Dim fso, objFile, objReg, Max, Min, str, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile("a.txt")
Set objReg = New RegExp
objReg.Pattern = "\bZ(-?\d*\.?\d+)\b"
Max = -9999 : Min = 9999
While Not objFile.AtEndOfStream
    str = objFile.ReadLine
    If objReg.Test(str) Then
        n = objReg.Execute(str)(0).SubMatches(0) * 1
        If n > Max Then Max = n
        If n < Min Then Min = n
    End If
Wend
MsgBox "Max=" & Max & " Min=" & MinCOPY

TOP

回复 13# raozhao2008


    你认为10#思路和你的JS有区别吗?

如果txt文件小,当然可以用ReadAll 速度也会快些
Dim fso, objReg, Max, Min, str, n
Set fso = CreateObject("Scripting.FileSystemObject")
str = fso.OpenTextFile("123.txt").ReadAll
Set objReg = New RegExp
objReg.Pattern = "\bZ(-?\d*\.?\d+)\b"
objReg.Global = True
For Each Match In objReg.Execute(str)
    n = Match.SubMatches(0) * 1
    If IsEmpty(Max) Or n > Max Then Max = n
    If IsEmpty(Min) Or n < Min Then Min = n
Next
MsgBox "Max=" & Max & " Min=" & MinCOPY

TOP

返回列表