Solved

Removing a certain tag in an HTML String

Posted on 2002-06-10
9
166 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 52

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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