<%
'取中间字符串
function getmidstr(L,R,str)
int_left=instr(str,L)
int_right=instr(str,R)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
If int_left>0 and int_right>0 Then
getmidstr=mid(str,int_left+len(L),int_right-int_left-len(L))
Else
getmidstr="执行的字符串中不包含“"&L&"”或“"&R&"”"
End If
end function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
str="www.goodtext.org"
response.write "<BR>"&getmidstr("go","xt",str)
’将输出"odte"
%>
扩展模式:
<%
'取中间字符串
function getmidstr(L,R,str,m,n)
'm,n为控制参数,表示输出的字符串将分别向左,向右多输出m,n个字符。
int_left=instr(str,L)
int_right=instr(str,R)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
if (m="left") then '若m为“left”,输出的字符串将包含左边部分(L),下同
m=len(L)
end if
if (n="right") then
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
n
=len(R)
end if
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
if (m>(len(L)+int_left-1)) then
m=(len(L)+int_left-1)
end if
If int_left>0 and int_right>0 Then
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
getmidstr
=mid(str,int_left+len(L)-m,int_right-int_left-len(L)+n+m)
Else
getmidstr="执行的字符串中不包含“"&L&"”或“"&R&"”"
End If
end function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
str="abcdefghijk"
response.write "<BR>"&getmidstr("bcd","hi",str,0,0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
‘输出
"efg"
response.write "<BR>"&getmidstr("bcd","hi",str,2,1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
‘输出
"cdefgh"
response.write "<BR>"&getmidstr("bcd","hi",str,"left","right")
‘输出"bcdefghi"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
%>
Tags:取中间字符串,ASP
思为网络腾讯企业微博,请关注我们: