zoukankan
html css js c++ java
UBB
参考了一些文章,整理了一下,大家可以直接拿去用吧,其实自从有了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(
"
"
,
"
"
);
#endregion
html标记符
#region
html标记符
sDetail
=
sDetail.Replace(
"
<
"
,
"
<
"
);
sDetail
=
sDetail.Replace(
"
>
"
,
"
>
"
);
#endregion
处[b][/b]标记
#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
处[i][/i]标记
#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
处[u][/u]标记
#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
处[p][/p]标记
#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
处[sup][/sup]标记
#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
处[sub][/sub]标记
#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
处
标记
//
处
标记
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
处[url=xxx][/url]标记
#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\
"
><IMG border=0 src=\
"
images
/
url.gif\
"
>
"
+
m.Groups[
3
].ToString()
+
"
</A>
"
);
}
#endregion
处[email][/email]标记
#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\
"
><IMG border=0 src=\
"
images
/
email.gif\
"
>
"
+
m.Groups[
2
].ToString()
+
"
</A>
"
);
}
#endregion
处[email=xxx][/email]标记
#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\
"
><IMG border=0 src=\
"
images
/
email.gif\
"
>
"
+
m.Groups[
3
].ToString()
+
"
</A>
"
);
}
#endregion
处[size=x][/size]标记
#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
处[color=x][/color]标记
#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
处[font=x][/font]标记
#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
处理[align=x][/align]
#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
处[H=x][/H]标记
#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
处理[list=x][*][/list]
#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(( )| )+)(?<正文>\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
}
}
查看全文
相关阅读:
ContactManager示例解析
CubeLiveWallpaper例子解析
BluetoothChat例子解析
推荐一个模板引擎 templateengine
jQuery plugin: Autocomplete
乐从网站建设、域名、主机-www.lecong.me-www.lecong.mobi
C#操作注册表
.NET模板引擎
[转]模版引擎AderTemplate源代码分析笔记
windows服务器文件同步,网站同步镜像
原文地址:https://www.cnblogs.com/LCX/p/110246.html
最新文章
VC:键盘钩子函数
转载:编写C#程序让其在Win7 下以管理员权限运行
VC :模板类
转载:c++修改文件(夹)的用户访问权限程序代码
摘录:C#应用程序运行时候检测Framework安装
VC:鼠标钩子函数
转载: C#高级编程:安装程序
转载:编写自动升级程序(思路)
双网卡双IP,实现南北互通
Linux流量监控工具 iftop (最全面的iftop教程)
热门文章
使用sqlmap进行sql注入
wget 使用技巧
linux下mongodb php驱动安装
nginx负载均衡实现
mongodb shell入门(一)概览
MySQL索引的使用
Centos5.6_X64使用yum快速搭建xen虚拟化环境
mongodb shell之使用js(二)
Android系统中的UI优化
Home例子研究
Copyright © 2011-2022 走看看