ASP 過濾數(shù)組重復數(shù)據(jù)函數(shù)(加強版)
更新時間:2010年05月31日 22:57:54 作者:
asp 不重復數(shù)組數(shù)據(jù)的實現(xiàn)代碼,比上個版本,更細,更能更強,大家可以根據(jù)需要選擇。
函數(shù)代碼:
<%'*******************************************************
'過濾數(shù)組重復函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數(shù)組下標時返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數(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%>
下面是測試代碼:
<%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 "字串為字符時:"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時:"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時:"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時,沒有超過下標時:"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時,超過下標時:"&array_no(s1,",",200)&"<br>"%>
測試結果:
字串為字符時:abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc
字串為數(shù)字時:1,2,3,11,22,33,12,13,14,333
字串為空時:沒有數(shù)據(jù)
字串為混合時:sdf,abc,12,2
字串為數(shù)組時:對不起,參數(shù)1不能為數(shù)組
字串為未知變量時:沒有數(shù)據(jù)
提取某一位時,沒有超過下標時:bb
提取某一位時,超過下標時:edc
腳本之家增強版本: 解決了數(shù)組常見錯誤
<%
'*******************************************************
'過濾數(shù)組重復函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數(shù)組下標時返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數(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 "字串為字符時:"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時:"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時:"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時,沒有超過下標時:"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時,超過下標時:"&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
復制代碼 代碼如下:
<%'*******************************************************
'過濾數(shù)組重復函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數(shù)組下標時返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數(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%>
下面是測試代碼:
復制代碼 代碼如下:
<%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 "字串為字符時:"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時:"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時:"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時,沒有超過下標時:"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時,超過下標時:"&array_no(s1,",",200)&"<br>"%>
測試結果:
復制代碼 代碼如下:
字串為字符時:abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc
字串為數(shù)字時:1,2,3,11,22,33,12,13,14,333
字串為空時:沒有數(shù)據(jù)
字串為混合時:sdf,abc,12,2
字串為數(shù)組時:對不起,參數(shù)1不能為數(shù)組
字串為未知變量時:沒有數(shù)據(jù)
提取某一位時,沒有超過下標時:bb
提取某一位時,超過下標時:edc
腳本之家增強版本: 解決了數(shù)組常見錯誤
復制代碼 代碼如下:
<%
'*******************************************************
'過濾數(shù)組重復函數(shù)名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數(shù)組下標時返回最后.
'使用于二維數(shù)組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
else
array_no = "對不起,參數(shù)3類型必需為數(shù)字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數(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 "字串為字符時:"&array_no(s1,",",0)&"<br>"
response.write "字串為數(shù)字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數(shù)組時:"&array_no(s5,",",0)&"<br>"
response.write "字串為未知變量時:"&array_no(s33,",",0)&"<br>"
response.write "提取某一位時,沒有超過下標時:"&array_no(s1,",",2)&"<br>"
response.write "提取某一位時,超過下標時:"&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
您可能感興趣的文章:
- asp取得數(shù)組中的最大值的方法
- asp下使用數(shù)組存放數(shù)據(jù)的代碼
- asp 得到動態(tài)數(shù)組中元素的個數(shù)
- asp.net 數(shù)組中字符串替換的幾種方式
- asp 動態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。
- asp.net 字符串、二進制、編碼數(shù)組轉換函數(shù)
- asp.net通過js實現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
- asp textarea 多行數(shù)組分割處理方法
- asp 數(shù)組 重復刪除函數(shù)(腳本之家增強版)
- ASP 使用Filter函數(shù)來檢索數(shù)組的實現(xiàn)代碼
- asp數(shù)組的使用介紹
- Asp與JS的數(shù)組和字符串下標介紹
- asp中使用redim、preserve創(chuàng)建動態(tài)數(shù)組實例
- ASP定義數(shù)組方法的技巧
相關文章
Vue2.0+ElementUI實現(xiàn)表格翻頁的實例
下面小編就為大家?guī)硪黄猇ue2.0+ElementUI實現(xiàn)表格翻頁的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10javascript實現(xiàn)生成并下載txt文件方式
這篇文章主要介紹了javascript實現(xiàn)生成并下載txt文件方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09javascript 隨機數(shù) 與高級應用 附vbscript(asp) 隨機數(shù)總結
有時忘了程序的隨機數(shù)函數(shù)或javascript和vbscript的隨機數(shù)混亂了,特總結下兩者的隨機數(shù)函數(shù),以備以后使用方便。2007-10-10html+css+js實現(xiàn)canvas跟隨鼠標的小圓特效源碼
這篇文章主要介紹了html+css+js實現(xiàn)canvas跟隨鼠標的小圓特效源碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03