本文整理汇总了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