473,700 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stripping HTML

I am trying to read in an HTML file and strip out the HTML
code so that all I have left is the text of the body.

Does anyone have any suggestions for doing this?
Any HTML stripping routines or objects that perform the
function?

Nov 20 '05 #1
5 2451
Public Function StripHTML(ByVal HTML As String) As String
Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos
mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1)
strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, "&nbsp;", " ")
strContent = Replace(strCont ent, "&amp;", "&")
strContent = Replace(strCont ent, "&quot;", "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "&lt;", "<")
strContent = Replace(strCont ent, "&gt;", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left(strContent , 1) =
Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in message
news:0e******** *************** *****@phx.gbl.. .
I am trying to read in an HTML file and strip out the HTML
code so that all I have left is the text of the body.

Does anyone have any suggestions for doing this?
Any HTML stripping routines or objects that perform the
function?

Nov 20 '05 #2
Cor
David,
Try to use mshtml.htmldocu ment
That gives a document in "DOM" document style.
If you are used to JavaScript it is easy to get the values then to process
this with the vVB.net language.
(tagname.innert ext)
Hopes this helps a little bit,
Cor
Nov 20 '05 #3
Thanks Charles. I will put this in my program and try it
out. I appreciate your help.
-----Original Message-----
Public Function StripHTML(ByVal HTML As String) As String Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1) strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, " ", " ")
strContent = Replace(strCont ent, "&", "&")
strContent = Replace(strCont ent, """, "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "<", "<")
strContent = Replace(strCont ent, ">", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left (strContent, 1) =Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in messagenews:0e******* *************** ******@phx.gbl. ..
I am trying to read in an HTML file and strip out the HTML code so that all I have left is the text of the body.

Does anyone have any suggestions for doing this?
Any HTML stripping routines or objects that perform the
function?

.

Nov 20 '05 #4
Cor
David,
You have to set the reference to Microsoft.mshtm l
You do that in the IDE by:Project, add reference, Microsoft.mshtm l(You can
do it too by right clicking on references in the soluction explorer.)
You better can not use an import when you have set a reference to this,
because then your IDE becomes terrible slow.
Use it like (as example) document as microsoft.mshtm l.document
Success
Cor
Nov 20 '05 #5
Charles,
I tried using your function by calling the function as
stripHTML(tData ToGet)
It get an invalid qualifer error in this line
strContent = HTML.Replace("</P>", vbCrLf)
And it highlights HTML.

Also on the line
Return strContent.Repl ace(vbCrLf, "<br>")
I get the error
Expected: end of statement

Any thoughts or ideas?
Thanks
-----Original Message-----
Public Function StripHTML(ByVal HTML As String) As String Dim strContent As String, mString As String
Dim mStartPos As Long, mEndPos As Long
Dim i, j

strContent = HTML.Replace("</P>", vbCrLf)
strContent = strContent.Repl ace("</p>", vbCrLf)

mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Do While mStartPos <> 0 And mEndPos <> 0 And mEndPos > mStartPos mString = Mid(strContent, mStartPos, mEndPos - mStartPos + 1) strContent = Replace(strCont ent, mString, "")
mStartPos = InStr(strConten t, "<")
mEndPos = InStr(strConten t, ">")
Loop
strContent = Replace(strCont ent, " ", " ")
strContent = Replace(strCont ent, "&", "&")
strContent = Replace(strCont ent, """, "'")
strContent = Replace(strCont ent, "&#", "#")
strContent = Replace(strCont ent, "<", "<")
strContent = Replace(strCont ent, ">", ">")
strContent = Replace(strCont ent, "%20", " ")
strContent = LTrim(Trim(strC ontent))
Do While Left(strContent , 1) = Chr(13) Or Left (strContent, 1) =Chr(10)
strContent = Mid(strContent, 2)
Loop
Return strContent.Repl ace(vbCrLf, "<br>")
End Function

"David Sawyer" <goldwings@_DEL ETE_msn.com> wrote in messagenews:0e******* *************** ******@phx.gbl. ..
I am trying to read in an HTML file and strip out the HTML code so that all I have left is the text of the body.

Does anyone have any suggestions for doing this?
Any HTML stripping routines or objects that perform the
function?

.

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4996
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore and, after submitting via POST to a preg_replace filter, get back '_sometext_' (i.e., the same thing with the literal backslashes stripped)
3
1734
by: Steveo | last post by:
I am currently stripping HTML from a string with the following code. (I know it's not the best way to strip HTML but bear with me) re.compile("<.*?>") I wanted to allow all H1 and H2 tags so i changed it to: re.compile("<*?>") This seemed to work but it also allowed the HTML tag(basically anythin
2
2309
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I should have been quiet about it, but then I would never be reimbursed. Oh well. I have been asked to write a program to ping a NetBIOS name, get the IP, and compare the 3rd octet to a list to get the computer's location. So far, I can ping the IP,...
258
8635
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
4
1256
by: Lance | last post by:
Hi, What way could I strip certain tags (like HTML comments) from the HTML being delivered to the client? I don't mean what regexp to use, but where do I put this stripping code? I'm thinking something in the Global.asax, but I can't find any reference to it having a Render or PreRender event or how to tie into them if I did! I'd ideally like some help along the lines of: 1 - Where to put the code 2 - example of how to alter the...
4
6667
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query string. However, in the code behind when I tried to get the query string value by calling Request.QueryString("QSParameter"), the value I got is: "<RowID>Chques</RowID>". The special character "è" has been stripped out. The web.config file is...
4
4159
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
7
3094
by: FFMG | last post by:
Hi, I have a form that allows users to comment, add entries and so on. But what a lot of them do is copy and paste directly from MS Word to my forms. almost all browsers will accept the post and give the impression that everything is saved properly. But, that is not the case when it comes time to displaying the message
3
1598
by: Michel Bouwmans | last post by:
Hey everyone, I'm trying to strip all script-blocks from a HTML-file using regex. I tried the following in Python: testfile = open('testfile') testhtml = testfile.read() regex = re.compile('<script\b*>(.*?)</script>', re.DOTALL) result = regex.sub('', blaat)
0
8713
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8639
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6556
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.