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


VB.NET Capture.Value屬性代碼示例

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


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

示例1: Example

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

Module Example
   Public Sub Main()
      Dim input As String = "Yes. This dog is very friendly."
      Dim pattern As String = "((\w+)[\s.])+"
      For Each match As Match In Regex.Matches(input, pattern)
         Console.WriteLine("Match: {0}", match.Value)
         For groupCtr As Integer = 0 To match.Groups.Count - 1
            Dim group As Group = match.Groups(groupCtr)
            Console.WriteLine("   Group {0}: {1}", groupCtr, group.Value)
            For captureCtr As Integer = 0 To group.Captures.Count - 1
               Console.WriteLine("      Capture {0}: {1}", captureCtr, _
                                 group.Captures(captureCtr).Value)
            Next
         Next                      
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:20,代碼來源:Capture.Value

輸出:

Match: Yes.
Group 0: Yes.
Capture 0: Yes.
Group 1: Yes.
Capture 0: Yes.
Group 2: Yes
Capture 0: Yes
Match: This dog is very friendly.
Group 0: This dog is very friendly.
Capture 0: This dog is very friendly.
Group 1: friendly.
Capture 0: This
Capture 1: dog
Capture 2: is
Capture 3: very
Capture 4: friendly.
Group 2: friendly
Capture 0: This
Capture 1: dog
Capture 2: is
Capture 3: very
Capture 4: friendly

示例2: Example

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

Module Example
   Public Sub Main()
      Dim pattern As String = "^([a-z]+)(\d+)?\.([a-z]+(\d)*)$"
      Dim values() As String = { "AC10", "Za203.CYM", "XYZ.CoA", "ABC.x170" }   
      For Each value In values
         Dim m As Match = Regex.Match(value, pattern, RegexOptions.IgnoreCase)
         If m.Success Then
            Console.WriteLine("Match: '{0}'", m.Value)
            Console.WriteLine("   Number of Capturing Groups: {0}", 
                              m.Groups.Count)
            For gCtr As Integer = 0 To m.Groups.Count - 1
               Dim group As Group = m.Groups(gCtr)
               Console.WriteLine("      Group {0}: {1}", gCtr, 
                                 If(group.Value = "", "<empty>", "'" + group.Value + "'"))   
               Console.WriteLine("         Number of Captures: {0}", 
                                 group.Captures.Count)
           
               For cCtr As Integer = 0 To group.Captures.Count - 1
                  Console.WriteLine("            Capture {0}: {1}", 
                                    cCtr, group.Captures(cCtr).Value)
               Next
            Next
         Else
            Console.WriteLine("No match for {0}: Match.Value is {1}", 
                              value, If(m.Value = String.Empty, "<empty>", m.Value))
         End If
      Next    
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Text.RegularExpressions,代碼行數:32,代碼來源:Capture.Value

輸出:

No match for AC10: Match.Value is 
Match: 'Za203.CYM'
Number of Capturing Groups: 5
Group 0: 'Za203.CYM'
Number of Captures: 1
Capture 0: Za203.CYM
Group 1: 'Za'
Number of Captures: 1
Capture 0: Za
Group 2: '203'
Number of Captures: 1
Capture 0: 203
Group 3: 'CYM'
Number of Captures: 1
Capture 0: CYM
Group 4: 
Number of Captures: 0
Match: 'XYZ.CoA'
Number of Capturing Groups: 5
Group 0: 'XYZ.CoA'
Number of Captures: 1
Capture 0: XYZ.CoA
Group 1: 'XYZ'
Number of Captures: 1
Capture 0: XYZ
Group 2: 
Number of Captures: 0
Group 3: 'CoA'
Number of Captures: 1
Capture 0: CoA
Group 4: 
Number of Captures: 0
Match: 'ABC.x170'
Number of Capturing Groups: 5
Group 0: 'ABC.x170'
Number of Captures: 1
Capture 0: ABC.x170
Group 1: 'ABC'
Number of Captures: 1
Capture 0: ABC
Group 2: 
Number of Captures: 0
Group 3: 'x170'
Number of Captures: 1
Capture 0: x170
Group 4: '0'
Number of Captures: 3
Capture 0: 1
Capture 1: 7
Capture 2: 0


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