分享
 
 
 

UBB(C#)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

参考了一些文章,整理了一下,大家可以直接拿去用吧,其实自从有了FreeTextBox这样的东东出现,UBB已经渐渐淡出江湖了。

using System;

using System.Text;

using System.Text.RegularExpressions;

namespace Test.Com

{

/// <summary>

/// 功能:UBB代码

/// 作者:Rexsp

/// 日期:2004-4-6

/// </summary>

public class UBB

{

#region 构造函数

public UBB()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

#endregion

#region 公共静态方法

/// <summary>

/// UBB代码处理函数

/// </summary>

/// <param name="sDetail">输入字符串</param>

/// <returns>输出字符串</returns>

public static string UBBToHTML(string sDetail)

{

Regex r;

Match m;

#region 处理空格

sDetail = sDetail.Replace(" ","&nbsp;");

#endregion

#region html标记符

sDetail = sDetail.Replace("<","&lt;");

sDetail = sDetail.Replace(">","&gt;");

#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.NextMatch())

{

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]标记

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 处[/url]标记

//处[url=xxx]标记

r = new Regex(@"(\+)])([ St]*?)([/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 处[email][/email]标记

//处[email][/email]标记

r = new Regex(@"([email])([ St]*?)([/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 处[email=xxx][/email]标记

//处[email=xxx][/email]标记

r = new Regex(@"([email=([ St]+)])([ St]*?)([/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 处[/size]标记

//处[size=x]标记

r = new Regex(@"()])([ St]*?)()",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]标记

//处[color=x]标记

r = new Regex(@"(+)])([ St]*?)()",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]标记

//处[font=x]标记

r = new Regex(@"(+)])([ St]*?)()",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("[url=file://%5Bpicture//%5D(//d+?)//%5B///picture//%5D%22,RegexOptions.IgnoreCase]\[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.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 处理换行

//处理换行,在每个新行的前面添加两个全角空格

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

return sDetail;

}

#endregion

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有