我已经获得了ASP代码。
<%
Dim body
body = "<h3>Arabian Test Adventures Tours & 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 & 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
%>
在上面的ASP代码中,我必须检查每个 SPAN class =“”convert“”,并用 USD替换所有<span class=""convert"">USD 50</span>@
50 ,所以在上面的代码我的两个
"<td><span class=""convert"">USD 50</span>@</td>"
"<td><span class=""convert"">USD 999</span>@</td>"
将被替换为如下
"<td>USD 50</td>"
"<td>USD 999</td>"
我正在尝试使用以下代码概念进行上述操作,但无法执行此操作
'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
请建议
答案 0 :(得分:2)
你好。当您需要进行复杂的字符串处理时,您应该使用Regex。它更有效,更简单 的 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