遇到了asp截取一个有规律的字符串,通过规律找到开始,结束,然后获取中间内容输出.
代码如下:
<%@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'开始字符串临时变量
'w--e_temp'结束字符串临时变量
'.--b_array'开始字符位置数组
'f--e_array'结束位置数组
'o--temp'函数中临时位置变量
'r--cutstr'开始字符串
'a--cutstr2'结束字符串
's--begin'开始位置
'p--minnum'位置最小值
'.--i'循环位置
'cn--falg'值如果为begin则求出开始字符串结束位置.如果不是,则是结束字符串位置
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原创,转载请注明
%>
结果如下:
cded
f
ixin
odjf
sdifj
中国足彩网信息请查看IT技术专栏
2025国考·省考课程试听报名