
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
570
|
Chapter 10: Regular Expressions
An options parameter of type RegexOptions has been added to the end of the last
method’s parameter list. This
Replace method uses this options parameter to define
how the
Regex object will use the regular expression. Note also that a constant
defaultOptions of type RegexOptions has been defined to provide a uniform way to
represent the default set of options in each overloaded method.
See Also
See the “.NET Framework Regular Expressions” topic in the MSDN documentation.
10.6 Augmenting the Basic String Replacement
Function
Problem
You need to replace character patterns within the target string with a new string.
However, in this case, each replacement operation has a unique set of conditions
that must be satisfied in order to allow the replacement to occur. Consider, for
example, that you receive a string containing information and you need to make glo-
bal modifications that will depend on a specific criterion.
Solution
Use the overloaded instance Replace method shown in Example 10-7 that accepts a
MatchEvaluator delegate along with its other parameters. The MatchEvaluator dele-
gate is a callback method that overrides the default behavior of the
Replace method.
{
return (ReplaceStrWithStr(source, matchPattern, replaceStr, count,
startPos, defaultOptions ...