Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2004, 01:51 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regex Problem

There is a problem with the code in the ProcessSpecialTags function in ForumsBusiness Helper.css.

If you use 2 or more of the same tag in a paragraph, the Regex.Replace function will treat everything in between the first opening tag and the last closing tag as one expression pattern. For instance, if you were using two I tags, then everything from the first opening tag to the second closing tag would appear in italics and the first closing tag and the second opening tag would be included in the text.

I actually ran into this issue on a major website recently. I couldn't include 2 or more links in the same sentence unless I put each one on a different line. Can anyone suggest a fix?


Thanks,

Claude
 
Old June 3rd, 2004, 02:36 AM
Authorized User
 
Join Date: Jul 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just found this problem too! There must be a way around this, just not sure how yet.
The textbox to post messages on this forum implements this correctly.

 
Old June 5th, 2004, 07:55 PM
Authorized User
 
Join Date: Jul 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Claude,
        I just figured out how to get more than one .. tag to render. Here is my implementation:

/////////////////////////////////////
public string ProcessSpecialTags(string stringToTransform)
        {


            StringBuilder formattedSource = new StringBuilder();
            string[] table = new string[2];

            table[0] = "<b>";
            table[1] = "</b>";
            MatchCollection matchs;
            // Look for code
            //
            matchs = Regex.Matches(stringToTransform, "\\[b\\](?<bold>(.|\\n)*?)\\[/b\\]", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);

            foreach (Match match in matchs)
            {

                // Get the formatted source code
                //
                formattedSource.Append(table[0]);
                formattedSource.Append(match.Groups["bold"].ToString());
                formattedSource.Append(table[1]);

                // Update the main string
                //
                stringToTransform = stringToTransform.Replace(match.ToString(), formattedSource.ToString());
                formattedSource.Remove( 0, formattedSource.Length );
            }


            return stringToTransform;
        }

//////////////////////////////////////

If you need real world example of this, check out the new ASP.NET Forums Beta RC2 application, in the Components solution, goto the Components folder, and then to the Transforms.cs file. Then goto line 403 or search for: SourceCodeMarkup(string stringToTransform)

My example above was adapted from the ASP.NET Forums code.

Hope this helps everyone,
d.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Regex problem cajedi Classic ASP Professional 0 December 7th, 2006 04:36 AM
ASP Regex problem cajedi Classic ASP Basics 0 December 7th, 2006 04:35 AM
REGEX Problem - Excel Hangs sreins VB How-To 0 December 5th, 2006 05:44 PM
More regex help Snib Pro PHP 4 December 16th, 2004 09:56 PM
Regex Help boyer99g General .NET 2 October 8th, 2004 05:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.