Imports System.Text.RegularExpressions
Class RegExSample
Shared Function CapText(m As Match) As String
' Get the matched string.
Dim x As String = m.ToString()
' If the first char is lower case...
If Char.IsLower(x.Chars(0)) Then
' Capitalize it.
Return Char.ToUpper(x.Chars(0)) + x.Substring(1, x.Length - 1)
End If
Return x
End Function
Public Shared Sub Main()
Dim text As String = "four score and seven years ago"
System.Console.WriteLine("text=[" + text + "]")
Dim result As String = Regex.Replace(text, "\w+", _
AddressOf RegExSample.CapText)
System.Console.WriteLine("result=[" + result + "]")
End Sub
End Class