StripHTML function

If you know the meaning of Strip word you will know what does it do.  just kidding 🙂

The StripHTML function removes all HTML code from a string.
Syntax:
string = StripHTML(string)
Example Usage:
<%
dim a

a = a & “<HTML>” & vbCrLf
a = a & “<HEAD>” & vbCrLf
a = a & “<TITLE>Rana’s Blog</TITLE>” & vbCrLf
a = a & “</HEAD>” & vbCrLf
a = a & “<BODY>” & vbCrLf
a = a & “-Code Project!!!” & vbCrLf
a = a & “<A href=”” mce_href=””./Rana.asp””></A>” & vbCrLf
a = a & “</BODY>” & vbCrLf
a = a & “</HTML>” & vbCrLf

response.write StripHTML(a)

%>

Output
Rana’s Blog – Code Project

One of my reader asked me how to do in ASP.NET 

In ASP.NET you can strip the HTML using Regex

Dim StrStripped As String

StrStripped = System.Text.RegularExpressions.Regex.Replace(“Input as String”, “Pattern like (.|\n)*?”, String.Empty)

Advertisements

3 thoughts on “StripHTML function

  1. I found this code from somewhere you can get customize according to your wish. thanks anyway.

    Function StripHTMLTag(ByVal sText)
    StripHTMLTag = “”
    fFound = False
    Do While InStr(sText, “<“)
    fFound = True
    StripHTMLTag = StripHTMLTag & ” ” & Left(sText, InStr(sText, “”) + 1)
    Loop
    StripHTMLTag = StripHTMLTag & sText
    If Not fFound Then StripHTMLTag = sText
    End Function

  2. If we add this instead of (.|\n)*? then it will work.

    For example:

    Dim StrStripped As String

    StrStripped = “ABC

    StrStripped = System.Text.RegularExpressions.Regex.Replace(StrStripped, “”, String.Empty)

    Response.Write(StrStripped)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s