Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

How to replace whole string text on runtime in ASP

Hi Experts,

I have got below ASP code.
    <%
    Dim body
    body = "<h3>Arabian Test Adventures Tours &amp; Safaris</h3>" 
    body = body &		"<table class=""dataTable"" cellspacing=""0"" cellpadding=""0"" width=""100%"">"
    body = body &			"<tbody>"
    body = body &				"<tr>"
    body = body &					"<th width=""40%"">Tour</th>"
    body = body &					"<th>Days</th>"
    body = body &					"<th>Adult*</th>"
    body = body &					"<th>Child*</th>"
    body = body &					"<th width=""20%"">AM/PM**</th>"
    body = body &				"</tr>"
    body = body &				"<tr>"
    body = body &					"<td><a title=""Dubai City Tour"" href=""tcm:232-203762""><strong>City of Merchants</strong></a>***"
    body = body &	"<br/>"
    body = body &	"Dubai City Tour</td>"
    body = body &					"<td>Daily</td>"
    body = body &					"<td><span class=""convert"">USD 50</span>@</td>"
    body = body &					"<td><span class=""convert"">USD 999</span>@</td>"
    body = body &					"<td>AM &amp; PM</td>"
    body = body &				"</tr>"
    body = body &			"</tbody>"
    body = body &		"</table>"
    Response.Write body
        'Do While InStr(body, "<span class=""convert""") > 0
    		body = left(body, InStr(body, "<span class=""convert"">")-1) & right(body, len(body) - InStr(body, "</span>@")-7)
    	'Loop
    Response.Write body
    %>

Open in new window


In above ASP code I have to check every **SPAN** having **class=""convert""** and will replace all the `<span class=""convert"">USD 50</span>@` with  **USD 50**, so in above code my both

    "<td><span class=""convert"">USD 50</span>@</td>"
    "<td><span class=""convert"">USD 999</span>@</td>" 

Open in new window


will be replaced like below

    "<td>USD 50</td>"
    "<td>USD 999</td>"

Open in new window


I am trying to do above things using below code concept, but not able to do that

    'Do While InStr(body, "<span class=""convert""") > 0
    		body = left(body, InStr(body, "<span class=""convert"">")-1) & right(body, len(body) - InStr(body, "</span>@")-7)
    	'Loop

Open in new window


Please suggest
Avatar of Ian Pattison
Ian Pattison
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you need to use the Replace function, not the "while instr..."

Consider:

body=Replace(body, "<span class=""convert"">", "")
body=Replace(body, "</span>@", "")
ASKER CERTIFIED SOLUTION
Avatar of matija_
matija_
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A simple REPLACE command is so much, well, simpler:
body = Replace(Replace(body, "<span class=""convert"">", ""), "</span>@", "")

Open in new window