Copy Code code as follows:
UBB code written by someone else
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 [b][/b] Mark
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 [i][/i] Mark
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 [u][/u] Mark
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] Mark
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] Mark
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] Mark
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 [Url][/url] Mark
Place [Url][/url] Mark
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 [Url=xxx][/url] Mark
Place [Url=xxx][/url] Mark
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 [Email][/email] Mark
Place [Email][/email] Mark
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 [Email=xxx][/email] Mark
Place [Email=xxx][/email] Mark
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 [Size=x][/size] Mark
Place [Size=x][/size] Mark
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 [Color=x][/color] Mark
Place [Color=x][/color] Mark
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] Mark
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 Working with 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] Mark
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 [list=x][*][/list]
processing [list=x][*][/list]
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 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
}
}
asp.net (C #) UBB processing class
Http://www.jb51.net/article/15615.htm