Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: How to: strip images from string w/ HTML inside


Message #1 by "Mike N" <mike@m...> on Wed, 11 Sep 2002 20:12:09
Hi,

I've got some HTML in a string, strContent.

Can anyone tell me how to use ASP to match and replace (remove, actually)
image tags from the HTML within that string?

For example, everything from 
<img src="all miscellaneous HTML until the closing bracket">

If I could turn it into a function, it would be double cool, but even a
simple command would be great.

Any help is greatly appreciated.
Thanks!

Mike
Message #2 by jeff.montgomery@m... on Thu, 12 Sep 2002 03:51:37
You need "regular expressions" or something that can replace text that 
fits a pattern, but isn't necessarily exactly the same each time:

Dim strStart, strLookfor, strReplacewith, strResult, myReg
strStart = "<td width=""170""><a href=""/""><img " & _
    "src=""/images/layout/headlogo.gif"" alt=""macworld"" " & _
    "width=""170""" height=""73"" border=""0""></a></td>"
strLookfor = "<img.+?>"
strReplacewith = ""
strResult = ""

Set myReg =  New RegExp
myReg.IgnoreCase = True
myReg.Global = True
myReg.Pattern = CStr(strLookfor)
strResult = myReg.Replace(CStr(strStart), CStr(strReplacewith))

Response.Write "RESULT: " & strResult


Jeff Montgomery
jeff.montgomery@m...

> Hi,

> I've got some HTML in a string, strContent.

> Can anyone tell me how to use ASP to match and replace (remove, actually)
i> mage tags from the HTML within that string?

> For example, everything from 
<> img src="all miscellaneous HTML until the closing bracket">

> If I could turn it into a function, it would be double cool, but even a
s> imple command would be great.

> Any help is greatly appreciated.
T> hanks!

> Mike

  Return to Index