7,765
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Type PointInfo
Name As String '点名
PX As String 'X坐标
PY As String 'Y坐标
PZ As String 'Z坐标
Size As String '尺寸
End Type
Private PointInfo() As PointInfo
Private Sub Command1_Click()
Dim testStr$
Dim i&
testStr = "END-POINT1 46105.35 3048.0 35.006 10" & vbCrLf & _
"END-POINT2 354.53 3535.000 2.500 25" & vbCrLf & _
"END-POINT3 389.000 853.053 83.354 66" & vbCrLf & _
"END-POINT4 354.000 35.03 75.035 35"
Call GetPointInfo(testStr) '处理
For i = LBound(PointInfo) To UBound(PointInfo) '检查结果
Debug.Print PointInfo(i).Name & "|" & PointInfo(i).PX & "|" & PointInfo(i).PY & "|" & PointInfo(i).PZ & "|" & PointInfo(i).Size
Next i
End Sub
Public Sub GetPointInfo(ByVal Source$)
On Error Resume Next
Dim RegExp As Object, Matches As Object
Dim i&
Set RegExp = CreateObject("VBscript.RegExp")
RegExp.Global = True
RegExp.Pattern = "(.*?) (\d+\.\d+) (\d+\.\d+) (\d+\.\d+) (\d+)" '这里仅以1个空格为例,如为多个不固定空格,处理后再用
Set Matches = RegExp.Execute(Source)
ReDim PointInfo(Matches.Count - 1)
For i = 0 To Matches.Count - 1
PointInfo(i).Name = Matches(i).SubMatches(0)
PointInfo(i).PX = Matches(i).SubMatches(1)
PointInfo(i).PY = Matches(i).SubMatches(2)
PointInfo(i).PZ = Matches(i).SubMatches(3)
PointInfo(i).Size = Matches(i).SubMatches(2)
Next i
Set RegExp = Nothing
Set Matches = Nothing
End Sub