asp实现替换指定规则的字符串
<%@ Language=VBScript %>
<%
Dim srcPath, dstPath ' 以“|”分隔的字符串
Dim srcPaths, dstPaths ' 分解后的数组
' 定义源字符串与目的字符串的对应关系,以“|”分隔
' /*****************只要修改这里*****************/
srcPath = "eastday/news|eastday/sports"
dstPath = "http://news.eastday.com|http://sports.eastday.com"
' /*****************只要修改这里*****************/
srcPaths = Split(srcPath, "|")
dstPaths = Split(dstPath, "|")
Function ReplaceURL(sURL)
Dim nIndex ' 计数器
If ((UBound(srcPaths) - LBound(srcPaths)) = (UBound(dstPaths) - LBound(dstPaths))) Then
For nIndex = LBound(srcPaths) To UBound(srcPaths)
If (Left(sURL, Len(srcPaths(nIndex))) = srcPaths(nIndex)) Then
sURL = Replace(sURL, srcPaths(nIndex), dstPaths(nIndex))
Exit For
End If
Next
End If
ReplaceURL = sURL
End Function
%>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
<%=ReplaceURL("eastday/news/userobject1ai234.html")%>
<br>
<%=ReplaceURL("eastday/sports/userobject1ai567.html")%>
</body>
</html>
<%
Dim srcPath, dstPath ' 以“|”分隔的字符串
Dim srcPaths, dstPaths ' 分解后的数组
' 定义源字符串与目的字符串的对应关系,以“|”分隔
' /*****************只要修改这里*****************/
srcPath = "eastday/news|eastday/sports"
dstPath = "http://news.eastday.com|http://sports.eastday.com"
' /*****************只要修改这里*****************/
srcPaths = Split(srcPath, "|")
dstPaths = Split(dstPath, "|")
Function ReplaceURL(sURL)
Dim nIndex ' 计数器
If ((UBound(srcPaths) - LBound(srcPaths)) = (UBound(dstPaths) - LBound(dstPaths))) Then
For nIndex = LBound(srcPaths) To UBound(srcPaths)
If (Left(sURL, Len(srcPaths(nIndex))) = srcPaths(nIndex)) Then
sURL = Replace(sURL, srcPaths(nIndex), dstPaths(nIndex))
Exit For
End If
Next
End If
ReplaceURL = sURL
End Function
%>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
<%=ReplaceURL("eastday/news/userobject1ai234.html")%>
<br>
<%=ReplaceURL("eastday/sports/userobject1ai567.html")%>
</body>
</html>