作者:sunqingfen5863 | 来源:互联网 | 2023-05-19 11:44
Imtryingtogetthecodebelowtosendtheresultsoftheregexpsearchtoanarrayofstrings.Ho
I'm trying to get the code below to send the results of the regexp search to an array of strings. How can I do that?
我正在尝试使用下面的代码将regexp搜索的结果发送到字符串数组。我怎样才能做到这一点?
When I change name to an array of strings i.e. Dim name() as String
VBA throws a type-mismatch exception. Any idea what I can do to fix that?
当我将名称更改为字符串数组时,即Dim name()作为字符串VBA引发类型不匹配异常。知道我能做些什么来解决这个问题吗?
Many thanks.
非常感谢。
Do While Not EOF(1)
Line Input #1, sText
If sText <> "" Then
Dim Regex As Object, myMatches As Object
' instantiates regexp object
Set Regex = CreateObject("Vbscript.RegExp")
With Regex
.MultiLine = False
.Global = True
.IgnoreCase = False
.Pattern = "^Personal\sname\s*[:]\s*"
End With
' get name, seperated from Personal Name
If Regex.test(sText) Then
Set myMatches = Regex.Execute(sText)
Dim temp As String
temp = Regex.Replace(sText, vbNullString)
Regex.Pattern = "^[^*]*[*]+"
Set myMatches = Regex.Execute(temp)
Dim temp2 As String
temp2 = myMatches.Item(0)
name = Trim(Left(temp2, Len(temp2) - 3))
End If
End If
Loop
2 个解决方案