本文整理匯總了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
輸出:
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
輸出:
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