这是我的代码:
Dim sPartIDNumberArray() As String
Dim strIn as String
...
Dim objRegex
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Global = True
.Pattern = "(\d{7})+"
sPartIDNumberArray = .Execute(strIn)
End With
FirstPartID = sPartIDNumberArray(1)
SecondPartID = sPartIDNumberArray(2)
我需要从文本字符串中提取两个7位数字,例如
点焊\ 3薄板\ 1384156 RE和1375188 ZB RE 20 PART 1
.Execute方法不应该在这里工作吗?我需要FirstPartID = 1384156和SecondPartID = 1375188
您不能将.Execute
method的结果分配给字符串数组。它返回一个IMatchCollection2
类型的对象。
这是应该起作用的代码:
Sub reg()
Dim objRegex As Object
Dim regexMatches As Object
Dim strIn As String
Dim FirstPartID As String
Dim SecondPartID As String
strIn = "Punktschweissen\3-Blech\1384156 RE und 1375188 ZB RE 20 PART 1"
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Global = True
.Pattern = "(\d{7})+"
Set regexMatches = .Execute(strIn)
End With
FirstPartID = regexMatches(0) 'sPartIDNumberArray(1)
SecondPartID = regexMatches(1) 'sPartIDNumberArray(2)
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句