homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

Remove image from HTML
Seems simple, but I am having the darndest time!

10+ Year Member

Msg#: 3391 posted 12:00 am on May 10, 2006 (gmt 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



10+ Year Member

Msg#: 3391 posted 12:25 am on May 10, 2006 (gmt 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.


10+ Year Member

Msg#: 3391 posted 3:26 pm on May 10, 2006 (gmt 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


WebmasterWorld Senior Member 10+ Year Member

Msg#: 3391 posted 4:40 pm on May 10, 2006 (gmt 0)

You need to use a vbscript regular expression... research RegExp.


5+ Year Member

Msg#: 3391 posted 10:05 pm on May 10, 2006 (gmt 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 %>


Global Options:
 top home search open messages active posts  

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved