Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing a certain tag in an HTML String

Posted on 2002-06-10
9
Medium Priority
?
170 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 54

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

971 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