程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> UBB(c#完整版)

UBB(c#完整版)

編輯:C#入門知識

using System;
using System.Text;
using System.Text.RegularExpressions;

namespace myluntan
{
 /// <summary>
 /// UBB 的摘要說明。
 /// </summary>
 public class UBB
 {
  public UBB()
  {
   //
   // TODO: 在此處添加構造函數邏輯
   //
  }
   
  #region 公共靜態方法
  /// <summary>
  /// UBB代碼處理函數
  /// </summary>
  /// <param name="sDetail">輸入字符串</param>
  /// <returns>輸出字符串</returns>
  public string UBBToHTML(string sDetail)
  {
   Regex r;
   Match m;
   #region 處理空格
   sDetail = sDetail.Replace(" ","&nbsp;");
   #endregion
   #region 處理單引號
   sDetail = sDetail.Replace("'","’");
   #endregion
   #region 處理雙引號
   sDetail = sDetail.Replace("\"","&quot;");
   #endregion
   #region html標記符
   sDetail = sDetail.Replace("<","&lt;");
   sDetail = sDetail.Replace(">","&gt;");
   
   #endregion
   #region 處理換行
   //處理換行,在每個新行的前面添加兩個全角空格
   r = new Regex(@"(\r\n((&nbsp;)| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<BR>  " + m.Groups["正文"].ToString());
   }
   //處理換行,在每個新行的前面添加兩個全角空格
   sDetail = sDetail.Replace("\r\n","<BR>");
   #endregion
   #region 處[b][/b]標記
   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]標記
   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]標記
   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]標記
   //處[p][/p]標記
   r = new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])",RegexOptions.IgnoreCase|RegexOptions.Singleline);
   for (m = r.Match(sDetail); m.Success; m = m.Next

[1] [2] [3] [4] [5] [6] [7] 下一頁  

Match())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
   }
   #endregion
   #region 處[sup][/sup]標記
   //處[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
   #region 處[sub][/sub]標記
   //處[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
   #region 處[url][/url]標記
   //處[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
   #region 處[url=xxx][/url]標記
   //處[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
   #region 處[email][/email]標記
   //處[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
   #region 處[email=xxx][/email]標記
   //處[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\">" +
    &n

上一頁  [1] [2] [3] [4] [5] [6] [7] 下一頁  

bsp;m.Groups[3].ToString() + "</A>");
   }
   #endregion
   #region 處[size=x][/size]標記
   //處[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
   #region 處[color=x][/color]標記
   //處[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
   #region 處[font=x][/font]標記
   //處[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 處理圖片鏈接
   //處理圖片鏈接
   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=\"點擊打開新窗口查看\" src=\"ShowImage.aspx?Action=forumImage&ImageID=" + m.Groups[1].ToString() +
     "\"></A>");
   }
   #endregion
   #region 處理[align=x][/align]
   //處理[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]標記
   //處[H=x][/H]標記
   r = new Regex(@"(\[H=([1-6])\])([ \S\t]*?)(\[\/H\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.

上一頁  [1] [2] [3] [4] [5] [6] [7] 下一頁  

NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<H" + m.Groups[2].ToString() + ">" +
     m.Groups[3].ToString() + "</H" + m.Groups[2].ToString() + ">");
   }
   #endregion
   #region 處理[list=x][*][/list]
   //處理[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 處[SHADOW=x][/SHADOW]標記
   //處[SHADOW=x][/SHADOW]標記
   r = new Regex(@"(\[SHADOW=)(\d*?),(#*\w*?),(\d*?)\]([\S\t]*?)(\[\/SHADOW\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<TABLE WIDTH=" + m.Groups[2].ToString() + "  STYLE=FILTER:SHADOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
     m.Groups[5].ToString() + "</TABLE>");
   }
   #endregion
   #region 處[glow=x][/glow]標記
   //處[glow=x][/glow]標記
   r = new Regex(@"(\[glow=)(\d*?),(#*\w*?),(\d*?)\]([\S\t]*?)(\[\/glow\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<TABLE WIDTH=" + m.Groups[2].ToString() + "  STYLE=FILTER:GLOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
     m.Groups[5].ToString() + "</TABLE>");
   }
   #endregion
   #region 處[center][/center]標記
   r = new Regex(@"(\[center\])([ \S\t]*?)(\[\/center\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<CENTER>" + m.Groups[2].ToString() + "</CENTER>");
   }
   #endregion
   #region 處[IMG][/IMG]標記
   r = new Regex(@"(\[IMG\])(http|https|ftp):\/\/([ \S\t]*?)(\[\/IMG\])",RegexOptions.IgnoreCase);
  

上一頁  [1] [2] [3] [4] [5] [6] [7] 下一頁  

 for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<br><a onfocus=this.blur() href=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " target=_blank><IMG SRC=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " border=0 alt=按此在新窗口浏覽圖片 onload=javascript:if(screen.width-333<this.width)this.width=screen.width-333></a>");
   }
   #endregion
   #region 處[em]標記
   r = new Regex(@"(\[em([\S\t]*?)\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<img src=pic/em" + m.Groups[2].ToString() + ".gif border=0 align=middle>");
   }
   #endregion
   #region 處[flash=x][/flash]標記
   //處[mp=x][/mp]標記
   r = new Regex(@"(\[flash=)(\d*?),(\d*?)\]([\S\t]*?)(\[\/flash\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<a href=" + m.Groups[4].ToString() + " TARGET=_blank><IMG SRC=pic/swf.gif border=0 alt=點擊開新窗口欣賞該FLASH動畫!> [全屏欣賞]</a><br><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><PARAM NAME=movie VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=" + m.Groups[4].ToString() + " quality=high menu=false pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + ">" + m.Groups[4].ToString() + "</embed></OBJECT>");
   }
   #endregion
   #region 處[dir=x][/dir]標記
   //處[dir=x][/dir]標記
   r = new Regex(@"(\[dir=)(\d*?),(\d*?)\]([\S\t]*?)(\[\/dir\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><param name=src value=" + m.Groups[4].ToString() + "><embed src=" + m.Groups[4].ToString() + " pluginspage=http://www.macromedia.com/shockwave/download/ width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "></embed></object>");
   }
   #endregion
   #region 處[rm=x][/rm]標記
   //處[rm=x][/rm]標記
   r = new Regex(@"(\[rm=)(\d*?),(\d*?)\]([\S\t]*?)(\[\/rm\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Group

上一頁  [1] [2] [3] [4] [5] [6] [7] 下一頁  

s[0].ToString(),
     "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><PARAM NAME=SRC VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=" + m.Groups[2].ToString() + "><PARAM NAME=SRC VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");
   }
   #endregion
   #region 處[mp=x][/mp]標記
   //處[mp=x][/mp]標記
   r = new Regex(@"(\[mp=)(\d*?),(\d*?)\]([\S\t]*?)(\[\/mp\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + " ><param name=ShowStatusBar value=-1><param name=Filename value=" + m.Groups[4].ToString() + "><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=" + m.Groups[4].ToString() + "  width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "></embed></object>");
   }
   #endregion
   #region 處[qt=x][/qt]標記
   //處[qt=x][/qt]標記
   r = new Regex(@"(\[qt=)(\d*?),(\d*?)\]([\S\t]*?)(\[\/qt\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<embed src=" + m.Groups[4].ToString() + " width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + " autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOF99v bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");
   }
   #endregion
   #region 處[QUOTE][/QUOTE]標記
   r = new Regex(@"(\[QUOTE\])([ \S\t]*?)(\[\/QUOTE\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<table cellpadding=0 cellspacing=0 border=1 WIDTH=94% bordercolor=#000000 bgcolor=#F2F8FF align=center  style=FONT-SIZE: 9pt><tr><td  ><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD >" + m.Groups[2].ToString() + "</table></table><br>");
   }
   #endregion
   #region 處[move][/move]標記
   r = new Regex(@"(\[move\])([ \S\t]*?)(\[\/move\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),

上一頁  [1] [2] [3] [4] [5] [6] [7] 下一頁  

"<MARQUEE scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
   }
   #endregion
   #region 處[FLY][/FLY]標記
   r = new Regex(@"(\[FLY\])([ \S\t]*?)(\[\/FLY\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<MARQUEE width=80% behavior=alternate scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
   }
   #endregion
   #region 處[image][/image]標記
   //處[image][/image]標記
   r = new Regex(@"(\[image\])([ \S\t]*?)(\[\/image\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<img src=\"" + m.Groups[2].ToString() + "\" border=0 align=middle><br>");
   }
   #endregion

   return sDetail;
  }
  #endregion
 }
}

 

上一頁  [1] [2] [3] [4] [5] [6] [7] 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved