Have you ever wanted to strip all of the HTML tags from a string? There are many reasons you may want to do this. For example, if you provide a feature on your site where a user can have the contents of a Web page emailed to them, you may wish to strip all of the HTML tags from the particular article for those users whose email client does not support HTML-formatted email.
Function stripHTML(strHTML)
'Strips the HTML tags from strHTML using split and join
'Ensure that strHTML contains something
If len(strHTML) = 0 then
stripHTML = strHTML
Exit Function
End If
dim arysplit, i, j, strOutput
arysplit = split(strHTML, "<") 'Assuming strHTML is nonempty, we want to start iterating 'from the 2nd array postition if len(arysplit(0)) > 0 then j = 1 else j = 0
'Loop through each instance of the array
for i=j to ubound(arysplit)
'Do we find a matching > sign?
if instr(arysplit(i), ">") then
'If so, snip out all the text between the start of the string
'and the > sign
arysplit(i) = mid(arysplit(i), instr(arysplit(i), ">") + 1)
else
'Ah, the < stroutput =" join(arysplit," stroutput =" mid(strOutput,"> to < and >
strOutput = replace(strOutput,">",">")
strOutput = replace(strOutput,"<","<")
stripHTML = strOutput
End Function
I update this blog when i am in the development mode, most of the times when I am developing systems, and i find new things that I believe are interesting, I post them on this blog, this helps me a lot too for future references and when i repeat the things i've already done. Hope this helps others too.
Thursday, October 20, 2005
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2005
(24)
-
▼
October
(10)
- How would you initialize the child class from the ...
- a great article on the inheritence in c#. This art...
- Have you ever wanted to strip all of the HTML tags...
- How to fix bugs in the Live / Production environme...
- Google Groups : microsoft.public.inetserver.iis
- A use case is a sequence of actions that provide a...
- Building Object Applications: Your Step-By-Step ...
- The Full-Lifecycle Object-Oriented Testing (FLOOT)...
- A fundamental concept of the Unified Modeling Lang...
- Project documentation and analysis is the most imp...
-
▼
October
(10)
No comments:
Post a Comment