Results 1 to 5 of 5

Thread: Quoting system problem..

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Quoting system problem..

    i am doing a kind of weblog in asp.net(using C#) but i am facing a problem..i want to put a quoting system..like this forum has..when the user puts [quote...[/quot..(i didnt put it so the forum didnt turn it into real quotes) it turns the thigns that are inside into a quote..my idea was when the user was posting the new it'd search for all the [quotes] and then would replace it for the HTML quote..but when adding it to the database(mssql 2k) i realised i couldnt do that because it wont accept me the ' symbol as it is a kind of"reserved word/simbol"..how should i do this? how the forums do this? thanks
    \m/\m/

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    My weblog http://blog.pjwc.com does what you are talking about. I got a piece of code from hellswraith that uses regular expressions to replace '[/quote] string and everything works fine when saving to the database. here is the code.
    Code:
    private string ProcessTags(string text)
    {
    	// Encode the text.
    	text = System.Web.HttpUtility.HtmlEncode(text);
    
    	// replace the bold special tags
    	text = Regex.Replace(text, "\\[B\\]", "<b>", RegexOptions.IgnoreCase);
    	text = Regex.Replace(text, "\\[/B\\]", "</b>", RegexOptions.IgnoreCase);
    			
    	// replace the underline special tags
    	text = Regex.Replace(text, "\\[U\\]", "<u>", RegexOptions.IgnoreCase);
    	text = Regex.Replace(text, "\\[/U\\]", "</u>", RegexOptions.IgnoreCase);
    			
    	// replace the italic special tags
    	text = Regex.Replace(text, "\\[I\\]", "<i>", RegexOptions.IgnoreCase);
    	text = Regex.Replace(text, "\\[/I\\]", "</i>", RegexOptions.IgnoreCase);
    
    	// replace the URL tag
    	text = Regex.Replace(text, "\\[URL\\](?<url>.*)\\[/URL\\]", "<a href=\"${url}\" target=\"_blank\">${url}</a>", RegexOptions.IgnoreCase);
    	text = Regex.Replace(text, "\\[IMG\\](?<img>.*)\\[/IMG\\]", "<img src=\"${img}\"/>", RegexOptions.IgnoreCase);
    
    	// replace the EMAIL tag
    	text = Regex.Replace(text, "\\[EMAIL\\](?<email>.*)\\[/EMAIL\\]", "<a href=\"mailto:${email}\">${email}</a>", RegexOptions.IgnoreCase);
    			
    	// replace the quote tags
    	text = Regex.Replace(text, "\\[QUOTE\\]", "<br><blockquote>quote:<hr height=\"1\" size=\"1\" noshade>", RegexOptions.IgnoreCase);
    	text = Regex.Replace(text, "\\[/QUOTE\\]","<hr height=\"1\" size=\"1\" noshade></blockquote><br>", RegexOptions.IgnoreCase);
    
    	// replace the new line and carriage return chars
    	text = text.Replace("\n", "<br>");
    	text = text.Replace("\r", "");
    
    	return text;
    }

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    does anyone has a regular expression to the following format?
    Quote Originally Posted by nick
    msg
    thanks
    \m/\m/

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    This is what I use for my forums:

    Code:
    encodedString = Regex.Replace(encodedString, "\\[quote=((.|\n)*?)\\]((.|\n)*?)\\[/quote\\]", GetQuoteBlock(),RegexOptions.IgnoreCase | RegexOptions.Compiled);	
    
    private static string GetQuoteBlock() {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table width=90% cellspacing=1 cellpadding=3 border=0 align=center>");
        sb.Append("<tr>");
        sb.Append("<td><span class=StandardText><b>$1 wrote:</b></span></td>");
        sb.Append("</tr>");   
        sb.Append("<tr>");
        sb.Append("<td class=quote>$3</td>");
        sb.Append("</tr>");
        sb.Append("</table>");
        return sb.ToString();
    }

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    oh tks
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width