开发者

How to replace whole string text on runtime in ASP

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
%>

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>" 

will be replaced like below

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

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

Please suggest


Hi. When you need doing complex string processing you should use Regex. It's more effective and more simply.
e.g.

Dim oReg, body
body = "your body content"
Set oReg = New RegExp
oReg.IgnoreCase = True
oReg.Global = True
oReg.Pattern = "<span class=""convert"">(USD \d+)</span>@"
body = oReg.Replace(body, "$1")
Response.Write body
Set oReg = Nothing
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜