我写入数据库的时候是从word上复制然后粘贴上去的,然后在页面上是用label控件读出来的,可是写入的时候,是有带word格式的,在用label读取的时候,label是空的,所以我想过滤那些格式,不知道怎么做,请各位前辈帮帮忙,看如何过滤下word格式在label上显示出来

解决方案 »

  1.   

    你是要把格式显示出来?还是把各式都去掉?基本思路就是写个函数,把格式符号替换显示出来:
    function word(string X)
    {
      读取X
      字符串处理函数 \n 替换 <br\> 其它类同
      retrun X
    }各式去掉:
    function word(string X)
    {
      读取X
      字符串处理函数 \n 替换 空格 其它类同
      retrun X
    }
      

  2.   

    好像是这样,比如你要把有各式的AAA
    BBB
    CCC转换成AAABBBCCC,替换格式符号就可以了。
      

  3.   

    对了,写入数据库的时候是从word粘贴?就是一个别人写好的编辑文本的组件?这样你写道数据库的时候就把各式一起写了么?那么LABLE读取的话,做字符过滤不久行了?
      

  4.   

    //清除word中的格式(C#)
    private string CleanWordHtml(string html)
            {
                StringCollection sc = new StringCollection();
                // get rid of unnecessary tag spans (comments and title)
                sc.Add(@"<!--(\w|\W)+?-->");
                sc.Add(@"<title>(\w|\W)+?</title>");
                // Get rid of classes and styles
                sc.Add(@"\s?class=\w+");
                sc.Add(@"\s+style='[^']+'");
                // Get rid of unnecessary tags
                //sc.Add(@"<(meta|link|/?o:|/?style|/?div|/?st\d|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>");
                sc.Add(@"<(meta|link|/?o:|/?style|/?font|/?strong|/?st\d|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>");
                // Get rid of empty paragraph tags
                sc.Add(@"(<[^>]+>)+ (</\w+>)+");
                // remove bizarre v: element attached to <img> tag
                sc.Add(@"\s+v:\w+=""[^""]+""");
                // remove extra lines
                sc.Add(@"(\n\r){2,}");
                foreach (string s in sc)
                {
                    html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);
                }
                return html;
            }