遇到了asp截取一個(gè)有規(guī)律的字符串,通過(guò)規(guī)律找到開(kāi)始,結(jié)束,然后獲取中間內(nèi)容輸出.
代碼如下:
<%@LANGUAGE = VBScript%>
<%Option Explicit%>
<%Dim str,b_temp,e_temp,b_array,e_array,temp,cutstr,cutstr2,begin,minnum,i,falg
'w--str'原有字符串
'w--b_temp'開(kāi)始字符串臨時(shí)變量
'w--e_temp'結(jié)束字符串臨時(shí)變量
'.--b_array'開(kāi)始字符位置數(shù)組
'f--e_array'結(jié)束位置數(shù)組
'o--temp'函數(shù)中臨時(shí)位置變量
'r--cutstr'開(kāi)始字符串
'a--cutstr2'結(jié)束字符串
's--begin'開(kāi)始位置
'p--minnum'位置最小值
'.--i'循環(huán)位置
'cn--falg'值如果為begin則求出開(kāi)始字符串結(jié)束位置.如果不是,則是結(jié)束字符串位置
str = "abcded,abf,abixin,abodjf,absdifj,"
Function get_b(str,cutstr,begin,flag)
temp = InStr(begin,str,cutstr)
If temp >0 Then
If flag = "begin" then
temp = temp+Len(cutstr)&","&get_b(str,cutstr,temp+1,flag)
Else
temp = temp&","&get_b(str,cutstr,temp+1,flag)
End if
Else
Exit function
End If
get_b = temp
End Function
Function min(num1,num2)
If num1>num2 Then min = num2 Else min = num1 End if
End function
cutstr = "ab"
begin = 1
cutstr2 = ","
b_temp = get_b(str,cutstr,begin,"begin")
e_temp = get_b(str,cutstr2,begin,"end")
b_array = Split(b_temp,",")
e_array = Split(e_temp,",")
'response.write UBound(b_array)&"=="&UBound(e_array)&"<br>"&b_temp&"<br>"&e_temp
minnum = min(UBound(b_array),UBound(e_array))
For i = 0 To minnum-1
response.write mid(str,b_array(i),(e_array(i)-b_array(i)))&"<br>"'輸出最后獲得的字符串
next
'www.forasp.cn原創(chuàng),轉(zhuǎn)載請(qǐng)注明
%>
結(jié)果如下:
cded
f
ixin
odjf
sdifj
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄