<%
'取中間字符串
function getmidstr(L,R,str)
int_left=instr(str,L)
int_right=instr(str,R)

If int_left>0 and int_right>0 Then
getmidstr=mid(str,int_left+len(L),int_right-int_left-len(L))
Else
getmidstr="執(zhí)行的字符串中不包含“"&L&"”或“"&R&"”"
End If
end function

str="www.goodtext.org"
response.write "<BR>"&getmidstr("go","xt",str)
’將輸出"odte"
%>
擴(kuò)展模式:
<%
'取中間字符串
function getmidstr(L,R,str,m,n)
'm,n為控制參數(shù),表示輸出的字符串將分別向左,向右多輸出m,n個字符。
int_left=instr(str,L)
int_right=instr(str,R)

if (m="left") then '若m為“l(fā)eft”,輸出的字符串將包含左邊部分(L),下同
m=len(L)
end if
if (n="right") then

n
=len(R)
end if

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

getmidstr
=mid(str,int_left+len(L)-m,int_right-int_left-len(L)+n+m)
Else
getmidstr="執(zhí)行的字符串中不包含“"&L&"”或“"&R&"”"
End If
end function

str="abcdefghijk"
response.write "<BR>"&getmidstr("bcd","hi",str,0,0)

‘輸出
"efg"
response.write "<BR>"&getmidstr("bcd","hi",str,2,1)

‘輸出
"cdefgh"
response.write "<BR>"&getmidstr("bcd","hi",str,"left","right")
‘輸出"bcdefghi"


%>
Tags:取中間字符串,ASP
思為網(wǎng)絡(luò)騰訊企業(yè)微博,請關(guān)注我們: