试图找出如何用相应的值查找和替换文本。
例如
1) fedex 到 FedEx 2) nasa 到 NASA 3) po box 到 PO BOX
Public Function FindReplace(ByVal s As String) As String
Dim MatchEval As New MatchEvaluator(AddressOf RegexReplace)
Dim Pattern As String = "(?<f1>fedex|nasa|po box)"
Return Regex.Replace(s, Pattern, MatchEval, RegexOptions.IgnoreCase)
End Function
Public Function RegexReplace(ByVal m As Match) As String
Select Case LCase(m.Groups("f1").Value)
Case "fedex"
Return "FedEx"
Case "nasa"
Return "NASA"
Case "po box"
Return "PO BOX"
End Select
End Function
上面的代码适用于固定值,但不知道如何使用上面的代码来匹配运行时添加的值,如 db 到 Db。