Article View: borland.public.csharpbuilder.language.csharp
Article #548Re: C# 2.0
From: Jon Shemitz
Date: Mon, 26 Jul 2004 06:07
Date: Mon, 26 Jul 2004 06:07
22 lines
1589 bytes
1589 bytes
public static string Replace(string Input, Regex R, string Pattern)
{
// Create an object[] with an entry for every capture group in R
object[] Groups = new object[R.GetGroupNumbers().Length];
// Pass Regex.Replace a C# 2.0 anonymous method
return R.Replace(Input, delegate(Match M)
{
M.Groups.CopyTo(Groups, 0);
return String.Format(Pattern, Groups);
} );
}
// substitute the {number} syntax of String.Format
// for the $number syntax of Match.Result
// give Rudy and Nick heart attacks.
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Technical Details
Message-ID:
<41049F97.B701E290@midnightbeach.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40FE138D.D0A0F368@midnightbeach.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,169d36351e297cad X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <41049F97.B701E290@midnightbeach.com> Date: Sun, 25 Jul 2004 23:07:19 -0700 From: Jon Shemitz <jon@midnightbeach.com> Reply-To: jon@midnightbeach.com Organization: Midnight Beach X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) X-Accept-Language: en-US,en MIME-Version: 1.0 Newsgroups: borland.public.csharpbuilder.language.csharp Subject: Re: C# 2.0 References: <40FE138D.D0A0F368@midnightbeach.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 63.249.65.27 X-Trace: newsgroups.borland.com 1090822040 63.249.65.27 (25 Jul 2004 23:07:20 -0700) Lines: 22 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail