Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing a certain tag in an HTML String

Posted on 2002-06-10
9
Medium Priority
?
169 Views
Last Modified: 2010-05-02
Greetings,

I have a variable holding an HTML file content what I want is the following:

Remove all the <a> tags from it, what I want is to capture the link tag and remove it with its contents whatever it is an image , or a text or anything

Please help

thnx
0
Comment
Question by:marounk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 7066424
HTMLString = Replace$(HTMLString,"<a>","") ?
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7066600
also this,
HTMLString = Replace$(HTMLString,"</a>","")

This will remove the hyperlinks from the htm page.

But as I understand from your code is you want to remove all the text within the <a> and </a> tags. If it is so, then find for <a> and </a> tags using mid or instr fns and replace that with vbnullstring(" ")

Hope this helps!

-priya



0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7067592
IMHO, you have two choices:
1) Second one by priya_pbk but changing the first to "<a" since there is not an "<A>" alone ;)
2) You could use HTMLDocument object.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:marounk
ID: 7069138
where can I find example on the HTMLDocument Object ???

thnx
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 300 total points
ID: 7070670
One possible solution:
'Set a reference to microsoft Intenet controls
'Set a rteference to microspft html object library
' try this:

Option Explicit

Dim WithEvents IE As InternetExplorer
Dim WithEvents iedoc As HTMLDocument

Dim sContents As String
Private Sub Form_Load()
Set IE = New InternetExplorer
With IE
    .navigate "www.experts-exchange.com/visualbasic/"
    .Visible = True
End With
End Sub


Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    Set iedoc = IE.document
    Dim lnk As HTMLLinkElement
    For Each lnk In iedoc.links
        lnk.disabled = True
    Next
End If
End Sub
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7072038
Richie, I tried your example, but gives me an error at this line , ie:
lnk.disabled = True

mentions "Object doesn't support this property or method"

I have put the references and wrote down the code, it opens the IE and then shows this error.

Was curious to know how the 'lnk.disabled=true' can actually disable links in a web page!! Am I missing something here.

-priya


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7072750
I did a test before post it with no problems!
Maybe a MSHTML.dll version problem?

marounk, that code didn't solve your problem?, then, why did you accept my comment as answer?
0
 
LVL 1

Author Comment

by:marounk
ID: 7074756
After adding the Refrences in VB you code did work but it is not finding any Links in any Page !!!

I did close this thread because I was desperate !

Thnx for caring
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7116971
Strange, i did a test with www.experts-exchange.com/visualbasic/ and everything worked fine.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question