【发布时间】:2020-01-07 18:07:33
【问题描述】:
对于 Access 开发,我使用了 GetOpenFilename 函数,如 here 所述 但是 lpstrTitle 是用特殊字符 SOH 设置的。为了删除 SOH,我创建了一个 regExp 函数
Public Function RegParse(sStr As String) '----> sStr is lpstrTitle from getopenfiled
Dim oRegex As New RegExp
sPattern = "^.*?(?=\x01)" '--> Failed on .Test
'sPattern = ^[^\x01]* '--> successful.Test but SOH still there
'sPattern = (^.*)v(.*) '-->Ok but v deleted
.Replace(sStr, "$1")
With oRegex
.IgnoreCase = True
.pattern = sPattern
.Global = False
If .Test(sStr) Then
sStr1 = .Execute(sStr)(0)
End With
End Function
但是 sStr1 仍然是 SOH 字符,sPattern = ^[^\x01]*
并且命令 sStr1 = .replace(sStr1, “$1”) 是不可能的,因为 sPattern = "^.*?(?=\x01) 在 .test 中失败
提前感谢您的帮助
【问题讨论】:
标签: vba regexp-replace