首页 文章

意外的结束声明

提问于
浏览
0

我越来越反复出现以下消息错误“第2行中的语句意外结束”我看不出有什么问题吗?我做错了什么..

Sub Main()
  Dim regex As Regex = New Regex("\d+")
  Dim match As Match = regex.Match("Dot 77 Perls")
  If match.Success Then
      MessageBox.Show(match.Value)
  End If
End Sub

1 回答

  • 5

    你将VB.NET语法与VBScript混合在一起,上面的代码应该像这样编写:

    Dim regex
    Set regex = CreateObject("VBScript.RegExp")
    
      regex.Pattern = "\d+"
    
      If regex.Test("Dot 77 Perls") Then
          WScript.Echo regex.Execute("Dot 77 Perls")(0)
      End If
    

    有关VBScript正则表达式引擎的更多信息,请参见this MSDN page

相关问题