Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从文本字符串中删除MS Office垃圾邮件_.net_Regex_Vb.net_Ssrs 2008_Ms Office - Fatal编程技术网

.net 从文本字符串中删除MS Office垃圾邮件

.net 从文本字符串中删除MS Office垃圾邮件,.net,regex,vb.net,ssrs-2008,ms-office,.net,Regex,Vb.net,Ssrs 2008,Ms Office,我有一个字符串,其中包含一堆MS Word垃圾,如下所示: 我尝试了下面的函数来删除它,但它们只删除了部分,并留下了大量空白: Public Function CleanOfficeJunk(html As String) As String ' start by completely removing all unwanted tags html = System.Text.RegularExpressions.Regex.Replace(html, "<[/]?(

我有一个字符串,其中包含一堆MS Word垃圾,如下所示:


我尝试了下面的函数来删除它,但它们只删除了部分,并留下了大量空白:

Public Function CleanOfficeJunk(html As String) As String
    ' start by completely removing all unwanted tags 
    html = System.Text.RegularExpressions.Regex.Replace(html, "<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    ' then run another pass over the html (twice), removing unwanted attributes 
    html = System.Text.RegularExpressions.Regex.Replace(html, "<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>", "<$1$2>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    html = System.Text.RegularExpressions.Regex.Replace(html, "<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>", "<$1$2>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    Return html
End Function
公共函数CleanOfficeJunk(html作为字符串)作为字符串
'首先完全删除所有不需要的标记
html=System.Text.RegularExpressions.Regex.Replace(html,“]*?>”,“”,System.Text.RegularExpressions.RegexOptions.IgnoreCase)
'然后在html上运行另一个过程(两次),删除不需要的属性
html=System.Text.RegularExpressions.Regex.Replace(html,“]*)(?:class | lang | style | size | face |[ovwxp]:\w+=(?:“[^']*”|【^\s>]+)([^>]*)>,”,System.Text.RegularExpressions.RegexOptions.IgnoreCase)
html=System.Text.RegularExpressions.Regex.Replace(html,“]*)(?:class | lang | style | size | face |[ovwxp]:\w+=(?:“[^']*”|【^\s>]+)([^>]*)>,”,System.Text.RegularExpressions.RegexOptions.IgnoreCase)
返回html
端函数
我在SQLServerReportingService(SSRS)报告中使用它,需要在文本框中显示字符串之前清除这些字符串

有没有更好的方法来移除这样的东西

编辑:我确实看到了这篇文章


但在我的情况下,接受的答案似乎不起作用。

您应该尝试将占位符属性设置为HTML。这解决了我的问题


您的字符串是否可能包含良好的
<或>
。如果不是,为什么不删除
<和>
中包含的所有内容……它可能包含一个
在这里或那里。ThanksLast问题,您是否只希望指定标记之间的文本?基本上只针对您需要的标签allow@Codexer我只想删除xml和样式标记之间的所有内容。如果有这样的事,你好。。。那我就留着吧谢谢