Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Remove image from HTML

Seems simple, but I am having the darndest time!

12:00 am on May 10, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 3, 2004
votes: 0

Shouldn't I be able to use Replace? I can't get it to work, and I know I am missing something simple. This is the code I am trying to use:

ad = "This is my image! <img src='example.gif'>"

ad = Replace(ad,"<img src*>","<!--Image Removed-->")

Any comments?

- Zak

12:25 am on May 10, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Nov 3, 2003
votes: 0

I don't code in .net or asp, but looking at your code, don't you want REREPLACE (regular expression replace), not replace. I think most languages separate out this functionality. The * will only work when calling a rereplace.

Call me a moron if .net doesn't work that way.

3:26 pm on May 10, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 3, 2004
votes: 0

There is no "rereplace" in ASP: At least not that I could find.

Does anyone know if "replace" won't allow regular expressions? And if not, what's the best method to get this done?

I fear that my only alternative is to turn "img src=" into "a" to make it an a-tag so that it won't display for now ... I would like to rid of the tag all together, but ...

I've been googling for hours and found no solutions ...

-- Zak

4:40 pm on May 10, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2003
votes: 0

You need to use a vbscript regular expression... research RegExp.
10:05 pm on May 10, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 3, 2005
votes: 0

You're using classic ASP, right?
You could just do a simple search on the beginning and end, and replace anything in between(the following isn't perfect, but I only spent a few minutes on it :P .. you should get the idea anyway )
Drop this page in your wwwroot and you can play with the start token, end token and the string to search and replace..

<% @Language="VBScript" %>
<% Option Explicit %>
Dim htmlOutput, outString
Dim tknStart, tknEnd, htmlSrc
If(Request.Form("btnSubmit") = "submit") Then
htmlOutput = StripBetweenTokens(Request.Form("tknStart"), Request.Form("tknEnd"), Request.Form("htmlSrc"))
End If
Function StripBetweenTokens(startToken, endToken, sourceString)
Dim sStart, sEnd
sStart = 0
sEnd = 0
sourceString = Replace(sourceString, """", "")
sStart = InStr(1, sourceString, startToken)
while(sStart > 0)
If(sStart > 0) Then
sEnd = InStr(sStart, sourceString, endToken)
If(sEnd > sStart) Then
sourceString = Replace(sourceString, Mid(sourceString, sStart, sEnd - sStart + Len(endToken)), "[REMOVED]")
StripBetweenTokens = "End Tag not found.. exiting"
Exit Function
End If
End If
sStart = InStr(1, sourceString, startToken)
outString = sourceString
StripBetweenTokens = outString
End Function
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name=ProgId content=VisualStudio.HTML>
<meta name=Originator content="Microsoft Visual Studio .NET 7.1">
<form action="RegexTest.asp" id="RegexTest" name="RegexTest" method="post">
Start Token:<input id="tknStart" size="10" name="tknStart" type="text" value="<% = Request.Form("tknStart") %>"><br>
End Token:<input id="tknEnd" name="tknEnd" size="10" type="text" value="<% = Request.Form("tknEnd") %>"><br>
Search Text:<input id="htmlSrc" name="htmlSrc" size="50" type="text" value="<% = Request.Form("htmlSrc") %>"><br>
<input id="btnSubmit" name="btnSubmit" type="submit" value="submit">
<% = htmlOutput %>