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ù)代碼:
<%'*******************************************************
'過濾數(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è)試代碼:
<%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é)果:
字串為字符時(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ò)誤
<%
'*******************************************************
'過濾數(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>"
%>
主要是增加了判斷
do while instr(cxstr1,",,")>0
cxstr1=replace(cxstr1,",,",",")
loop
if right(cxstr1,1)="," then
cxstr1=left(cxstr1,len(cxstr1)-1)
end if
復(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
您可能感興趣的文章:
- asp取得數(shù)組中的最大值的方法
- asp下使用數(shù)組存放數(shù)據(jù)的代碼
- asp 得到動(dòng)態(tài)數(shù)組中元素的個(gè)數(shù)
- asp.net 數(shù)組中字符串替換的幾種方式
- asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。
- asp.net 字符串、二進(jìn)制、編碼數(shù)組轉(zhuǎn)換函數(shù)
- asp.net通過js實(shí)現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
- asp textarea 多行數(shù)組分割處理方法
- asp 數(shù)組 重復(fù)刪除函數(shù)(腳本之家增強(qiáng)版)
- ASP 使用Filter函數(shù)來檢索數(shù)組的實(shí)現(xiàn)代碼
- asp數(shù)組的使用介紹
- Asp與JS的數(shù)組和字符串下標(biāo)介紹
- asp中使用redim、preserve創(chuàng)建動(dòng)態(tài)數(shù)組實(shí)例
- ASP定義數(shù)組方法的技巧
相關(guān)文章
Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁的實(shí)例
下面小編就為大家?guī)硪黄猇ue2.0+ElementUI實(shí)現(xiàn)表格翻頁的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10javascript實(shí)現(xiàn)生成并下載txt文件方式
這篇文章主要介紹了javascript實(shí)現(xiàn)生成并下載txt文件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09js實(shí)現(xiàn)Select列表各項(xiàng)上移和下移的方法
這篇文章主要介紹了js實(shí)現(xiàn)Select列表各項(xiàng)上移和下移的方法,涉及javascript動(dòng)態(tài)操作頁面元素屬性值的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08javascript 隨機(jī)數(shù) 與高級(jí)應(yīng)用 附vbscript(asp) 隨機(jī)數(shù)總結(jié)
有時(shí)忘了程序的隨機(jī)數(shù)函數(shù)或javascript和vbscript的隨機(jī)數(shù)混亂了,特總結(jié)下兩者的隨機(jī)數(shù)函數(shù),以備以后使用方便。2007-10-10html+css+js實(shí)現(xiàn)canvas跟隨鼠標(biāo)的小圓特效源碼
這篇文章主要介紹了html+css+js實(shí)現(xiàn)canvas跟隨鼠標(biāo)的小圓特效源碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03