VB icon

Trim HTML from an ASP String (exceptions to certain HTML tags can be made)

Email
Submitted on: 1/5/2015 1:28:00 PM
By: Bingo Solutions (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: ASP (Active Server Pages)
Views: 3043
 
     Use the TrimHTML function to remove any HTML strings from the text. Also, when you can specify certain tags which you DONT want it to remove. This is especially useful when you want to allow your users to be able to specify certain tags like or . It is simple function which can save great deal of time. At first, I like the prebuilt HTMLEncode function provided with ASP but again, it removed all HTML tags and did not give opputunity for us to make exceptions to certain formatting tags like . I hope you like it and please vote for me!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Trim HTML from an ASP String (exceptions to certain HTML tags can be made)
' Description:Use the TrimHTML function to remove any HTML strings from the text. Also, when you can specify certain tags which you DONT want it to remove. This is especially useful when you want to allow your users to be able to specify certain tags like <B> or <I>. It is simple function which can save great deal of time. At first, I like the prebuilt HTMLEncode function provided with ASP but again, it removed all HTML tags and did not give opputunity for us to make exceptions to certain formatting tags like <B>. I hope you like it and please vote for me!
' By: Bingo Solutions (from psc cd)
'**************************************

INSTRUCTIONS:
Call the function from you code like below:
strResults=TrimHTML ("Plain Text.<BR><B>Should be bold!</B><BR><b>Should be bold</B><BR><i>should be italics</i><BR><B><I>Bold + italics!</B></i>","b,i,BR")
In this case, strRestuls will hold the new text. Notice that I have specified 3 tags which I dont want it to remove from the string. You can do as many as you want but remember that you should not put the "<" and ">" around them when calling this function.
If you want it to remove all HTML tags, then use then specify "" as the second perimeter when calling the function... heres an example:
strResults=TrimHTML ("Plain Text.<BR><B>Should be bold!</B><BR><b>Should be bold</B><BR><i>should be italics</i><BR><B><I>Bold + italics!</B></i>","")
---------------------------------------
<%
strResults=TrimHTML ("Plain Text.<BR><B>Should be bold!</B><BR><b>Should be bold</B><BR><i>should be italics</i><BR><B><I>Bold + italics!</B></i>","")
 Response.Write strResults
Function TrimHTML (strHTML,arrDontTrim)
 strHTML=Replace(strHTML,"<","<")
strHTML=Replace(strHTML,">",">")
If len(arrDontTrim)<>0 Then
arrDontTrim=Split(arrDontTrim,",")
For i = 0 to ubound(arrDontTrim)
strHTML=Replace(strHTML,"<" & arrDontTrim(i) & ">","<" & arrDontTrim(i) & ">",1, -1, vbTextCompare)
strHTML=Replace(strHTML,"</" & arrDontTrim(i) & ">","</" & arrDontTrim(i) & ">",1, -1, vbTextCompare)
Next
End If
 TrimHTMl= strHTML
End Function
%>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.