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