我的content字段(是text类型的) 里面有很多UBB代码 请问谁知道用C#语句怎么过滤掉吗?只保留汉字

解决方案 »

  1.   


    public static string UbbToHtml(string inputStr)
            {
                return Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(HtmlEncode(inputStr).Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"), @"\[B\](.*?)\[\/B\]", "<B>$1</B>", RegexOptions.IgnoreCase), @"\[U\](.*?)\[\/U\]", "<U>$1</U>", RegexOptions.IgnoreCase), @"\[I\](.*?)\[\/I\]", "<I>$1</I>", RegexOptions.IgnoreCase), @"\[ALIGN.*?=(.*?)\](.*?)\[\/ALIGN\]", "<DIV ALIGN='$1'>$2</DIV>", RegexOptions.IgnoreCase), @"\[em(.*?)\]", "<img src='" + Param.ApplicationRootPath + "/images/post/pic/em$1.gif'/>", RegexOptions.IgnoreCase);
            }这是转换到HTML的, 你把html标签删除就是光杆内容了.
    如:@"\[B\](.*?)\[\/B\]", "$1", RegexOptions.IgnoreCase), @"\[U\](.*?)\[\/U\]", "$1", 
      

  2.   

    2楼的兄弟 系统提示HtmlEncode、Param不存在 HtmlEncode、Param在那定义的呀?
      

  3.   


    汗....忘记删除里面的方法了.
    public static string UbbToHtml(string inputStr)
            {
                return Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(Regex.Replace(inputStr.Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"), @"\[B\](.*?)\[\/B\]", "<B>$1</B>", RegexOptions.IgnoreCase), @"\[U\](.*?)\[\/U\]", "<U>$1</U>", RegexOptions.IgnoreCase), @"\[I\](.*?)\[\/I\]", "<I>$1</I>", RegexOptions.IgnoreCase), @"\[ALIGN.*?=(.*?)\](.*?)\[\/ALIGN\]", "<DIV ALIGN='$1'>$2</DIV>", RegexOptions.IgnoreCase), @"\[em(.*?)\]", "<img src='/images/post/pic/em$1.gif'/>", RegexOptions.IgnoreCase);
            }这样试试