Craig,
You can use a MatchEvaluator (a delegate) to call a routine for each match
you find, then you can simply call Regex.Replace with your pattern & the
AddressOf your routine. The routine will take the inner stuff found & return
the new value.
Something like:
Regex.Replace(S ubject, "(\&|\"")", AddressOf Match_Craig)
Private Function Match_Craig(ByV al m As Match) As String
Select Case m.Groups[0].Value
case "&"
return "&"
case """"
return "'"
End Select
End Function
However I don't think I would use a RegEx in this case, I think I would use
StringBuilder.R eplace in this case as you are replacing based on fixed
words, not on patterns. RegEx.Replace are better are replacing based on
patterns. ("\&" is a fixed pattern, unlike "9*" which is a variable
pattern).
Dim sb As New StringBuilder(S ubject)
sb.Replace("&", "&")
sb.Replace("""" , "'")
Subject = sb.ToString();
Remember there are three Split functions in .NET:
Use Microsoft.Visua lBasic.Strings. Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.
Use System.String.S plit if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.
Use System.Text.Reg ularExpressions .RegEx.Split to split based
on matching patterns.
Hope this helps
Jay
"Craig Buchanan" <so*****@micros oft.com> wrote in message
news:e$******** ******@tk2msftn gp13.phx.gbl...
Is there a way to combine these two Replace into a single line?
Regex.Replace(S ubject, "\&", "&")
Regex.Replace(S ubject, "\'", "'")
Perhaps Regex.Replace(S ubject, "{\&|\'}", "{&|'} ")
Thanks,
Craig