當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Match類代碼示例

本文整理匯總了VB.NET中System.Text.RegularExpressions.Match的典型用法代碼示例。如果您正苦於以下問題:VB.NET Match類的具體用法?VB.NET Match怎麽用?VB.NET Match使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Match類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim input As String = "Dim values() As Integer = { 1, 2, 3 }" & vbCrLf & _
                            "For ctr As Integer = values.GetLowerBound(1) To values.GetUpperBound(1)" & vbCrLf & _
                            "   Console.Write(values(ctr))" & vbCrLf & _
                            "   If ctr < values.GetUpperBound(1) Then Console.Write("", "")" & vbCrLf & _
                            "Next" & vbCrLf & _
                            "Console.WriteLine()"   
      Dim pattern As String = "Console\.Write(Line)?"
      Dim matches As MatchCollection = Regex.Matches(input, pattern)
      For Each match As Match In matches
         Console.WriteLine("'{0}' found in the source code at position {1}.", _ 
                           match.Value, match.Index)       
      Next                            
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:19,代碼來源:Match

輸出:

Console.Write' found in the source code at position 115.
Console.Write' found in the source code at position 184.
Console.WriteLine' found in the source code at position 211.

示例2: Example

' 導入命名空間
Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim input As String = "Dim values() As Integer = { 1, 2, 3 }" & vbCrLf & _
                            "For ctr As Integer = values.GetLowerBound(1) To values.GetUpperBound(1)" & vbCrLf & _
                            "   Console.Write(values(ctr))" & vbCrLf & _
                            "   If ctr < values.GetUpperBound(1) Then Console.Write("", "")" & vbCrLf & _
                            "Next" & vbCrLf & _
                            "Console.WriteLine()"   
      Dim pattern As String = "Console\.Write(Line)?"
      Dim match As Match = Regex.Match(input, pattern)
      Do While match.Success
         Console.WriteLine("'{0}' found in the source code at position {1}.", _ 
                           match.Value, match.Index)
         match = match.NextMatch()                  
      Loop                            
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:20,代碼來源:Match

輸出:

Console.Write' found in the source code at position 115.
Console.Write' found in the source code at position 184.
Console.WriteLine' found in the source code at position 211.

示例3:

' Search for a pattern that is not found in the input string.
Dim pattern As String = "dog"
Dim input As String = "The cat saw the other cats playing in the back yard."
Dim match As Match = Regex.Match(input, pattern)
If match.Success Then
   ' Report position as a one-based integer.
   Console.WriteLine("'{0}' was found at position {1} in '{2}'.", _ 
                     match.Value, match.Index + 1, input)
Else
   Console.WriteLine("The pattern '{0}' was not found in '{1}'.", _
                     pattern, input)
End If
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:12,代碼來源:Match


注:本文中的System.Text.RegularExpressions.Match類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。