- this is some text
ASP.NET: Strip HTML tags from a string
From Wiki
Summary: Strip HTML Tags from a string
If you have a string containing HTML and you need to strip all of the HTML out of it, one of the easiest methods is to use a Regular Expression.
Here's a simple example that shows how to use this expression:
- Imports System.Text.RegularExpressions
- Partial Class Default1
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Dim myHTML As String = "<html><head></head><body style=""color:blue;"">this is some text</body></html>"
- Response.Write(ConvertHtmlToPlainText(myHTML))
- End Sub
- Private Function ConvertHtmlToPlainText(ByVal htmlText As String) As String
- Return Regex.Replace(htmlText, "<[^>]*>", String.Empty)
- End Function
- End Class
Ouptut:
This Hack is part of the ASP.NET Hacks collection


