[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to replace whole string text on runtime in ASP

Posted on 2011-09-08
3
Medium Priority
?
218 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:tia_kamakshi
[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
3 Comments
 
LVL 10

Expert Comment

by:CSIPComputing
ID: 36502108
I think you need to use the Replace function, not the "while instr..."

Consider:

body=Replace(body, "<span class=""convert"">", "")
body=Replace(body, "</span>@", "")
0
 
LVL 6

Accepted Solution

by:
matija_ earned 2000 total points
ID: 36502316
Try with Regular Expressions function:

<%
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 Replacing(body)

Function Swap(x, y, z)
	If IsNull(x) then Exit Function

	Dim RegEx
	Set RegEx = New RegExp
	With RegEx
		.Global = True
		.IgnoreCase = True
		.Pattern = y
	End with
	Swap = RegEx.Replace(x, z)
	Set RegEx = Nothing
End Function

Function Replacing(x)
	x = Swap(x, "<span class=""convert"">(.*?)</span>", "$1")
	Replacing = x
End Function
%>

Open in new window

0
 
LVL 29

Expert Comment

by:Badotz
ID: 36507062
A simple REPLACE command is so much, well, simpler:
body = Replace(Replace(body, "<span class=""convert"">", ""), "</span>@", "")

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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