<%
strO="abcdefg<pre>h001</pre>abcdefg<pre>h002</pre>abcdefg<pre>h003</pre>abcdefg<pre>h004</pre>3"
response.write strO & "<br>"
strNew=f_replace_middle(strO,"<pre>","</pre>","OK")
response.write strNew
function f_replace_middle(strO,strA,strB,strN)
'替换strA和strB中间的字符串成新字符串
lengthA=len(strA)
lengthB=len(strB)
lengthN=len(strN)
insA=instr(strO,strA)
do while insA>0
insB=instr(insA+lengthA,strO,strB)
if insB>0 then
strO=left(strO,insA-1) & strN & mid(strO,insB+lengthB) '变成新字符串
insA=instr(strO,strA)'对于新字符串指针必须重新来
else
exit do
end if
loop
f_replace_middle=strO
end function
%>
运行结果是:
abcdefg
h001
abcdefg
h002
abcdefg
h003
abcdefg
h004
3
abcdefgOKabcdefgOKabcdefgOKabcdefgOK3