UBB (C #)

Source: Internet
Author: User
Refer to a number of articles, sorted out, we can take it directly, in fact, since the freetextbox such things appear, UBB has gradually faded out of the lake. Using System;
Using System.Text;
Using System.text.regularexpressions;namespace test.com
{
<summary>
Function: UBB Code
Author: rexsp
Date: 2004-4-6
</summary>
public class UBB
{
#region Constructors
Public UBB ()
{
//
TODO: Add constructor logic here
//
}
#endregion #region public static method
<summary>
UBB Code handler function
</summary>
<param name= "Sdetail" > Input string </param>
<returns> Output String </returns>
public static string ubbtohtml (String sdetail)
{
Regex R;
Match m; #region Process Spaces
Sdetail = Sdetail.replace ("", "");
#endregion #region HTML tag
Sdetail = Sdetail.replace ("<", "<");
Sdetail = Sdetail.replace (">", ">");
#endregion #region Marks
R = new Regex (\[b\]) ([\s\t]*?) (\[\/b\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<B>" + m.groups[2]. ToString () + "</B>");
}
#endregion #region Marks
R = new Regex (\[i\]) ([\s\t]*?) (\[\/i\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<I>" + m.groups[2]. ToString () + "</I>");
}
#endregion #region Marks
R = new Regex (\[u\]) ([\s\t]*?) (\[\/u\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<U>" + m.groups[2]. ToString () + "</U>");
}
#endregion #region [p][/p] Tag
Place [p][/p] Mark
R = new Regex ((\ r \ n) *\[p\]) (. *?) ((\ r \ n) *\[\/p\]) ", regexoptions.ignorecase| Regexoptions.singleline);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<p class=\" pstyle\ ">" + m.groups[3]. ToString () + "</P>");
}
#endregion #region [Sup][/sup] Tag
Place [Sup][/sup] Mark
R = new Regex (\[sup\]) ([\s\t]*?) (\[\/sup\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<SUP>" + m.groups[2]. ToString () + "</SUP>");
}
#endregion #region [Sub][/sub] Tag
Place [Sub][/sub] Mark
R = new Regex (\[sub\]) ([\s\t]*?) (\[\/sub\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<SUB>" + m.groups[2]. ToString () + "</SUB>");
}
#endregion #region Marks
Place marked
R = new Regex (\[url\]) ([\s\t]*?) (\[\/url\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<a href=\" "+ m.groups[2]. ToString () + "\" target=\ "_blank\" > "+
M.GROUPS[2]. ToString () + "</A>");
}
#endregion #region Marks
Place marked
R = new Regex (\[url= ([\s\t]+) \]) ([\s\t]*?) (\[\/url\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<a href=\" "+ m.groups[2]. ToString () + "\" target=\ "_blank\" > "+
M.GROUPS[3]. ToString () + "</A>");
}
#endregion #region Marks
Place marked
R = new Regex (\[email\]) ([\s\t]*?) (\[\/email\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<a href=\" mailto: "+ m.groups[2". ToString () + "\" target=\ "_blank\" > "+
M.GROUPS[2]. ToString () + "</A>");
}
#endregion #region Marks
Place marked
R = new Regex (\[email= ([\s\t]+) \]) ([\s\t]*?) (\[\/email\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<a href=\" mailto: "+ m.groups[2". ToString () + "\" target=\ "_blank\" > "+
M.GROUPS[3]. ToString () + "</A>");
}
#endregion #region Marks
Place marked
R = new Regex (@ (\[size= ([1-7]) \]) ([\s\t]*?) (\[\/size\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<font size=" + m.groups[2]. ToString () + ">" +
M.GROUPS[3]. ToString () + "</FONT>");
}
#endregion #region Marks
Place marked
R = new Regex (\[color= ([\s]+) \]) ([\s\t]*?) (\[\/color\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<font color=" + m.groups[2]. ToString () + ">" +
M.GROUPS[3]. ToString () + "</FONT>");
}
#endregion #region [Font=x][/font] Tag
Place [Font=x][/font] Mark
R = new Regex (\[font= ([\s]+) \]) ([\s\t]*?) (\[\/font\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<font face=" + m.groups[2]. ToString () + ">" +
M.GROUPS[3]. ToString () + "</FONT>");
}
#endregion #region Process Picture links
Working with picture links
R = new Regex ("\\[picture\\]" (\\d+?) \\[\\/picture\\] ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<a href=\" showimage.aspx? Type=all&action=forumimage&imageid= "+ m.groups[1]. ToString () +
"\" target=\ "_blank\" ><img border=0 title=\ "Click to open a new window to view \" Src=\ "Showimage.aspx? Action=forumimage&imageid= "+ m.groups[1]. ToString () +
"></A>");
}
#endregion #region processing [align=x][/align]
processing [align=x][/align]
R = new Regex (\[align= ([\s]+) \]) ([\s\t]*?) (\[\/align\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"<p align=" + m.groups[2]. ToString () + ">" +
M.GROUPS[3]. ToString () + "</P>");
}
#endregion #region [h=x][/h] Tag
Place [h=x][/h] Mark
R = new Regex (@ (\[h= ([1-6]) \]) ([\s\t]*?) (\[\/h\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (),
"M.GROUPS[3]. ToString () + "}
#endregion #region Processing

Processing

R = new Regex (@[List (= (a|a| i|i| )? \] ([\s\t]*) \ r \ n) ((\[\*\] ([\s\t]*\r\n)) *?) (\[\/list\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
String Strli = M.groups[5]. ToString ();
Regex RLI = new Regex (@ "\[\*\] ([\s\t]*\r\n?)", regexoptions.ignorecase);
Match MLI;
for (MLI = Rli.match (Strli); mli.success; MLI = Mli.nextmatch ())
{
Strli = Strli.replace (Mli.groups[0]. ToString (), "<LI>" + mli.groups[1]);
} Sdetail = Sdetail.replace (m.groups[0). ToString (),
"<ul type=\" "+ m.groups[3]. ToString () + "\" ><B> "+ m.groups[4]." ToString () + "</B>" +
Strli + "</UL>");
}
#endregion #region to handle line wrapping
To handle wrapping, add two full-width spaces before each new row
R = new Regex (@) (\ r \ n () |) +) (?< body >\s+) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<BR>" + m.groups["body"]. ToString ());
}
To handle wrapping, add two full-width spaces before each new row
Sdetail = Sdetail.replace ("\ r \ n", "<BR>");
#endregion return sdetail;
}
#endregion}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.