欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP 過濾數(shù)組重復(fù)數(shù)據(jù)函數(shù)(加強(qiáng)版)

 更新時(shí)間:2010年05月31日 22:57:54   作者:  
asp 不重復(fù)數(shù)組數(shù)據(jù)的實(shí)現(xiàn)代碼,比上個(gè)版本,更細(xì),更能更強(qiáng),大家可以根據(jù)需要選擇。
函數(shù)代碼:
復(fù)制代碼 代碼如下:

<%'*******************************************************
'過濾數(shù)組重復(fù)函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動(dòng)識(shí)別
'cxstr2:cxstr1中分割符號(hào)。
'cxstr3:提取結(jié)果中的某一位置字串,等于0時(shí)返回為全部,大于數(shù)組下標(biāo)時(shí)返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對(duì)不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對(duì)不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對(duì)不起,參數(shù)1不能為數(shù)組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
array_no = "沒有數(shù)據(jù)"
Exit Function
end if
ss = split(cxstr1,cxstr2)
cxs=cxstr2&ss(0)&cxstr2
sss=cxs
for m = 0 to ubound(ss)
cc = cxstr2&ss(m)&cxstr2
if instr(sss,cc)=0 then
sss = sss&ss(m)&cxstr2
end if
next
array_no = right(sss,len(sss)-len(cxstr2))
array_no = left(array_no,len(array_no)-len(cxstr2))
if cxstr3 <> 0 then
cx_sp = split(array_no,cxstr2)
if cxstr3 > ubound(cx_sp) then
array_no = cx_sp(ubound(cx_sp))
else
array_no = cx_sp(cxstr3)
end if
end if
end function%>


下面是測(cè)試代碼:
復(fù)制代碼 代碼如下:

<%s1 = "abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc"
s2 = "1,2,3,11,22,33,12,13,14,11,33,333,14"
s3 = ""
s4 = "sdf,abc,12,2,2,abc"
s5 = split(s4)
response.write "字串為字符時(shí):"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時(shí):"&array_no(s2,",",0)&"<br>"
response.write "字串為空時(shí):"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時(shí):"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時(shí):"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時(shí):"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時(shí),沒有超過下標(biāo)時(shí):"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時(shí),超過下標(biāo)時(shí):"&array_no(s1,",",200)&"<br>"%>

測(cè)試結(jié)果:
復(fù)制代碼 代碼如下:

字串為字符時(shí):abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc
字串為數(shù)字時(shí):1,2,3,11,22,33,12,13,14,333
字串為空時(shí):沒有數(shù)據(jù)
字串為混合時(shí):sdf,abc,12,2
字串為數(shù)組時(shí):對(duì)不起,參數(shù)1不能為數(shù)組
字串為未知變量時(shí):沒有數(shù)據(jù)
提取某一位時(shí),沒有超過下標(biāo)時(shí):bb
提取某一位時(shí),超過下標(biāo)時(shí):edc


腳本之家增強(qiáng)版本: 解決了數(shù)組常見錯(cuò)誤
復(fù)制代碼 代碼如下:

<%
'*******************************************************
'過濾數(shù)組重復(fù)函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動(dòng)識(shí)別
'cxstr2:cxstr1中分割符號(hào)。
'cxstr3:提取結(jié)果中的某一位置字串,等于0時(shí)返回為全部,大于數(shù)組下標(biāo)時(shí)返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對(duì)不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對(duì)不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對(duì)不起,參數(shù)1不能為數(shù)組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
array_no = "沒有數(shù)據(jù)"
Exit Function
end if
do while instr(cxstr1,",,")>0
cxstr1=replace(cxstr1,",,",",")
loop
if right(cxstr1,1)="," then
cxstr1=left(cxstr1,len(cxstr1)-1)
end if
ss = split(cxstr1,cxstr2)
cxs=cxstr2&ss(0)&cxstr2
sss=cxs
for m = 0 to ubound(ss)
cc = cxstr2&ss(m)&cxstr2
if instr(sss,cc)=0 then
sss = sss&ss(m)&cxstr2
end if
next
array_no = right(sss,len(sss)-len(cxstr2))
array_no = left(array_no,len(array_no)-len(cxstr2))
if cxstr3 <> 0 then
cx_sp = split(array_no,cxstr2)
if cxstr3 > ubound(cx_sp) then
array_no = cx_sp(ubound(cx_sp))
else
array_no = cx_sp(cxstr3)
end if
end if
end function

s1 = "abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc,333,,,,,333,7,,,,"
s2 = "1,2,3,11,22,33,12,13,14,11,33,333,14,333,,,,,333,7,,,,"
s3 = ""
s4 = "sdf,abc,12,2,2,abc,333,,,,,333,7,,,,"
s5 = split(s4)
response.write "字串為字符時(shí):"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時(shí):"&array_no(s2,",",0)&"<br>"
response.write "字串為空時(shí):"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時(shí):"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時(shí):"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時(shí):"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時(shí),沒有超過下標(biāo)時(shí):"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時(shí),超過下標(biāo)時(shí):"&array_no(s1,",",200)&"<br>"
%>

主要是增加了判斷
復(fù)制代碼 代碼如下:

do while instr(cxstr1,",,")>0
cxstr1=replace(cxstr1,",,",",")
loop
if right(cxstr1,1)="," then
cxstr1=left(cxstr1,len(cxstr1)-1)
end if

相關(guān)文章

最新評(píng)論