UBB(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(" "," ");
#endregion
#region 处理单引号
sDetail = sDetail.Replace("'","’");
#endregion
#region 处理双引号
sDetail = sDetail.Replace(""",""");
#endregion
#region html标记符
sDetail = sDetail.Replace("<","<");
sDetail = sDetail.Replace(">",">");
#endregion
#region 处理换行
//处理换行,在每个新行的前面添加两个全角空格
r = new Regex(@"(rn(( )| )+)(?<正文>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("rn","<BR>");
#endregion
#region 处[b][/b]标记
r = new Regex(@"([b])([ St]*?)([/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])([ St]*?)([/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])([ St]*?)([/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(@"((rn)*[p])(.*?)((rn)*[/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">" +
相关新闻>>
- 发表评论
-
- 最新评论 更多>>