Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata