本文整理匯總了VB.NET中System.Text.RegularExpressions.MatchEvaluator代理的典型用法代碼示例。如果您正苦於以下問題:VB.NET MatchEvaluator代理的具體用法?VB.NET MatchEvaluator怎麽用?VB.NET MatchEvaluator使用的例子?那麽, 這裏精選的代理代碼示例或許可以為您提供幫助。
在下文中一共展示了MatchEvaluator代理的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Module1
' 導入命名空間
Imports System.Text.RegularExpressions
Module Module1
Public Sub Main()
Dim sInput, sRegex As String
' The string to search.
sInput = "aabbccddeeffcccgghhcccciijjcccckkcc"
' A very simple regular expression.
sRegex = "cc"
Dim r As Regex = New Regex(sRegex)
' Assign the replace method to the MatchEvaluator delegate.
Dim myEvaluator As MatchEvaluator = New MatchEvaluator(AddressOf ReplaceCC)
' Write out the original string.
Console.WriteLine(sInput)
' Replace matched characters using the delegate method.
sInput = r.Replace(sInput, myEvaluator)
' Write out the modified string.
Console.WriteLine(sInput)
End Sub
Public Function ReplaceCC(ByVal m As Match) As String
' Replace each Regex match with the number of the match occurrence.
static i as integer
i = i + 1
Return i.ToString() & i.ToString()
End Function
End Module
輸出:
aabbccddeeffcccgghhcccciijjcccckkcc aabb11ddeeff22cgghh3344iijj5566kk77