CopyCode The Code is as follows: // UBB code written by someone else
Using system;
Using system. text;
Using system. Text. regularexpressions;
Namespace test. com
{
/// <Summary>
/// Function: UBB Code
/// By rexsp
/// Date: 2004-4-6
/// </Summary>
Public class UBB
{
# Region Constructor
Public UBB ()
{
//
// Todo: add the constructor logic here
//
}
# Endregion
# Region Public static method
/// <Summary>
/// UBB code processing function
/// </Summary>
/// <Param name = "sdetail"> input string </param>
/// <Returns> output string </returns>
Public static string ubbtohtml (string sdetail)
{
RegEx R;
Match m;
# Region processing space
Sdetail = sdetail. Replace ("","");
# Endregion
# Region HTML Tag
Sdetail = sdetail. Replace ("<", "<");
Sdetail = sdetail. Replace (">", "> ");
# Endregion
# MARK [B] [/B] At Region
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
# [I] [/I] Mark at region
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
# [U] [/u] Mark at region
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
# [P] [/P] Mark at region
// Mark [p] [/P]
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
# [Sup] [/sup] Mark at region
// Mark [sup] [/sup]
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
# [Sub] [/sub] Mark at region
// Mark [sub] [/sub]
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
# [Url] [/url] Mark at region
// Mark [url] [/url]
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
# [Url = xxx] [/url] Mark at region
// Mark [url = xxx] [/url]
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
# [Email] [/Email] Mark at region
// Mark [email] [/Email]
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
# [Email = xxx] [/Email] Mark at region
// Mark [email = xxx] [/Email]
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
# [Size = x] [/size] Mark at region
// Mark [size = x] [/size]
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
# [Color = x] [/color] Mark at region
// Mark [color = x] [/color]
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
# [Font = x] [/font] Mark at region
// Mark [font = x] [/font]
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 image links
// Process image 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]
// Process [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
# [H = x] [/h] Mark at region
// Mark [H = x] [/h]
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 (),
"<H" + M. Groups [2]. tostring () + ">" +
M. groups [3]. tostring () + "</H" + M. Groups [2]. tostring () + "> ");
}
# Endregion
# Region processing [list = x] [*] [/LIST]
// Process [list = x] [*] [/LIST]
R = new RegEx (@ "(\ [list (= (a | A | 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 process line feed
// Process line breaks and add two spaces at the beginning of each new line
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 ());
}
// Process line breaks and add two spaces at the beginning of each new line
Sdetail = sdetail. Replace ("\ r \ n", "<br> ");
# Endregion
Return sdetail;
}
# Endregion
}
}
Asp.net (C #) UBB processing class
Http://www.jb51.net/article/15615.htm