Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

How to modify the value of a named capture before doing a replace?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DotNetNewbie - 10 Apr 2008 22:04 GMT
Hello,

I have a regex and I want to modify the value of a named capture
before doing the regex.Replace.

So something like:

string text = Regex.Replace(oldText, myRegex, @"<a href="$1">$1</a>",
regexOptions);

Now I want to modify the value of the second $1 just in case it is too
long to display.

This doesn't work, but this is what I want to do somehow!

string text = Regex.Replace(oldText, myRegex,
                        String.Format(@"<a href="$1">{0}</a>",
MyFunction("$1")),
                      regexOptions);
Marc Gravell - 10 Apr 2008 22:26 GMT
Try:

       string text = Regex.Replace(oldText, myRegex, delegate (Match
match) {
           string capture1 = match.Captures[0].Value;
           return string.Format(@"<a href=""{0}"">{1}</a>",
               capture1, MyFunction(capture1));
       }, regexOptions);

Marc
DotNetNewbie - 21 Apr 2008 18:36 GMT
> Try:
>
[quoted text clipped - 6 lines]
>
> Marc

Marc, it didn't compile for some reason (i.e. there is not method that
takes in a delegate?)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.