Strip HTML from string in SSRS 2005 (VB.NET)

一曲冷凌霜 提交于 2019-12-30 06:07:52

问题


my SSRS DataSet returns a field with HTML, e.g.

<b>blah blah </b><i> blah </i>.

how do i strip all the HTML tags? has to be done with inline VB.NET

Changing the data in the table is not an option.

Solution found ... = System.Text.RegularExpressions.Regex.Replace(StringWithHTMLtoStrip, "<[^>]+>","")


回答1:


Thanx to Daniel, but I needed it to be done inline ... here's the solution:

= System.Text.RegularExpressions.Regex.Replace(StringWithHTMLtoStrip, "<[^>]+>","")

Here are the links:

http://weblogs.asp.net/rosherove/archive/2003/05/13/6963.aspx
http://msdn.microsoft.com/en-us/library/ms157328.aspx




回答2:


Here's a good example using Regular Expressions: http://www.4guysfromrolla.com/webtech/042501-1.shtml




回答3:


If you know the HTML is well-formed enough, you could, if you make sure it has a root node, convert the data in that field into a System.Xml.XmlDocument and then get the InnerText value from it.

Again, you will have to make sure the text has a root node, which you can add yourself if needs be, since it will not matter, and make sure the HTML is well formed.




回答4:


If you don't want to use regular expressions (for example if you need better performance) you could try a small method I wrote a while ago, posted at CodeProject.




回答5:


I would go to Report Properties and then code and add the following

Dim mRemoveTagRegex AS NEW System.Text.RegularExpressions.Regex("<(.|\n)+?>", System.Text.RegularExpressions.RegexOptions.Compiled)

Function RemoveHtml(ByVal text As string) AS string
  If text IsNot Nothing Then
    Return mRemoveTagRegex.Replace(text, "")
  End If 
End Function

Then you can use Code.RemoveHtml(Fields!Content.Value) to remove the html tags.

In my opinion this is preferable then having multiple copies of the regex.



来源:https://stackoverflow.com/questions/34926/strip-html-from-string-in-ssrs-2005-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!