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


VB.NET Match.NextMatch方法代碼示例

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


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

示例1: Example

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

Module Example
   Public Sub Main()
      Dim text As String = "One car red car blue car"
      Dim pattern As String = "(\w+)\s+(car)"

      ' Instantiate the regular expression object.
      Dim r As Regex = new Regex(pattern, RegexOptions.IgnoreCase)

      ' Match the regular expression pattern against a text string.
      Dim m As Match = r.Match(text)
      Dim matchcount as Integer = 0
      Do While m.Success
         matchCount += 1
         Console.WriteLine("Match" & (matchCount))
         Dim i As Integer
         For i = 1 to 2
            Dim g as Group = m.Groups(i)
            Console.WriteLine("Group" & i & "='" & g.ToString() & "'")
            Dim cc As CaptureCollection = g.Captures
            Dim j As Integer 
            For j = 0 to cc.Count - 1
              Dim c As Capture = cc(j)
               Console.WriteLine("Capture" & j & "='" & c.ToString() _
                  & "', Position=" & c.Index)
            Next 
         Next 
         m = m.NextMatch()
      Loop
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:33,代碼來源:Match.NextMatch

輸出:

Match1
Group1='One'
Capture0='One', Position=0
Group2='car'
Capture0='car', Position=4
Match2
Group1='red'
Capture0='red', Position=8
Group2='car'
Capture0='car', Position=12
Match3
Group1='blue'
Capture0='blue', Position=16
Group2='car'
Capture0='car', Position=21

示例2: Example

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

Module Example
   Public Sub Main()
      Dim pattern As String = "a*"
      Dim input As String = "abaabb"
      
      Dim m As Match = Regex.Match(input, pattern)
      Do While m.Success
         Console.WriteLine("'{0}' found at index {1}.", 
                           m.Value, m.Index)
         m = m.NextMatch()
      Loop         
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:16,代碼來源:Match.NextMatch

輸出:

a' found at index 0.
found at index 1.
aa' found at index 2.
found at index 4.
found at index 5.
found at index 6.


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