asp.net ubb USES code

  • 2020-05-07 19:27:59
  • OfStack


//// Other people write ubb code  

using System; 
using System.Text; 
using System.Text.RegularExpressions; 
namespace Test.Com 
{ 
/// <summary> 
///  Function: UBB code  
///  The author: Rexsp 
///  Date: 2004-4-6 
/// </summary> 
public class UBB 
{ 
#region  The constructor  
public UBB() 
{ 
// 
// TODO:  Add the constructor logic here  
// 
} 
#endregion 
#region  Public static method  
/// <summary> 
/// UBB Code handler  
/// </summary> 
/// <param name="sDetail"> Input string </param> 
/// <returns> Output string </returns> 
public static string UBBToHTML(string sDetail) 
{ 
Regex r; 
Match m; 
#region  Processing the blank space  
sDetail = sDetail.Replace(" "," "); 
#endregion 
#region html markers  
sDetail = sDetail.Replace("<","<"); 
sDetail = sDetail.Replace(">",">"); 
#endregion 
#region  place [b][/b] tag  
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  place [i][/i] tag  
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  place [u][/u] tag  
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  place [p][/p] tag  
// place [p][/p] tag  
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  place [sup][/sup] tag  
// place [sup][/sup] tag  
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  place [sub][/sub] tag  
// place [sub][/sub] tag  
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  place [url][/url] tag  
// place [url][/url] tag  
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\"><IMG border=0 src=\"images/url.gif\">" + 
m.Groups[2].ToString() + "</A>"); 
} 
#endregion 
#region  place [url=xxx][/url] tag  
// place [url=xxx][/url] tag  
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\"><IMG border=0 src=\"images/url.gif\">" + 
m.Groups[3].ToString() + "</A>"); 
} 
#endregion 
#region  place [email][/email] tag  
// place [email][/email] tag  
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\"><IMG border=0 src=\"images/email.gif\">" + 
m.Groups[2].ToString() + "</A>"); 
} 
#endregion 
#region  place [email=xxx][/email] tag  
// place [email=xxx][/email] tag  
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\"><IMG border=0 src=\"images/email.gif\">" + 
m.Groups[3].ToString() + "</A>"); 
} 
#endregion 
#region  place [size=x][/size] tag  
// place [size=x][/size] tag  
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  place [color=x][/color] tag  
// place [color=x][/color] tag  
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  place [font=x][/font] tag  
// place [font=x][/font] tag  
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  Handle image links  
// Handle 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 \" src=\"ShowImage.aspx?Action=forumImage&ImageID=" + m.Groups[1].ToString() + 
"\"></A>"); 
} 
#endregion 
#region  To deal with [align=x][/align] 
// To deal with [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  place [H=x][/H] tag  
// place [H=x][/H] tag  
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  To deal with [list=x][*][/list] 
// To deal with [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  Processing line  
// Process the newline by adding two full - Angle Spaces before each new line  
r = new Regex(@"(\r\n(( )| )+)(?< The body of the >\S+)",RegexOptions.IgnoreCase); 
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 
{ 
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<BR>  " + m.Groups[" The body of the "].ToString()); 
} 
// Process the newline by adding two full - Angle Spaces before each new line  
sDetail = sDetail.Replace("\r\n","<BR>"); 
#endregion 
return sDetail; 
} 
#endregion 
} 
} 


asp.net (c#) ubb handles classes
//www.ofstack.com/article/15615.htm

Related articles: