请问在前台多行文本框中输入UBB代码,在后台用C#是怎么样将UBB转换为HTML的,我用
 
public string ubbtohtml(string sDetail)
{
   Regex r;
   Match m;
   r = new Regex(@"(\[b\])([ \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>");
   }
 
   return sDetail;
}

这样的代码,可是一点作用也没有。还有C#中将UBB转换为HTML的正则表达式都是怎么写的,会不会是我的正则表达式写错了?有谁知道这几个问题怎么解的,帮帮我,谢谢。

解决方案 »

  1.   

    这样处理?格式都不在了。。你只要提取类似这样的内容?[abc]要提取的内容,不要前后的中框号[/abc]
      

  2.   

    UBB 是啥格式,一直没用过.
    请举个要转换的例子.
      

  3.   

    功能     写法     解析
    字体尺寸  [size={0}]{1}[/size]  <span style="font-size: {0}">{1}</span>
    颜色  [color={0}]{1}[/color]  <span style="color: {0}">{1}</span>
    字体加粗  {0}  <strong>{0}</strong>
    字体斜体  {0}  <em>{0}</em>
    字体带下滑线  {0}  <span style="text-decoration: underline">{0}</span>
    字体带删除线  {0}  <span style="text-decoration: line-through">{0}</span>
    内容居左显示 
    {0}
      

  4.   

    #region 处<strong></strong>标记
       r = new Regex(@"(\[b\])([ \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\])([ \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\])([ \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\])([ \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\])([ \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\])([ \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 处xxx标记
       //处xxx标记
       r = new Regex(@"(\[url=([ \t]+)\])([ \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
    部分代码,仅供参考。