asp 數(shù)組 重復(fù)刪除函數(shù)(腳本之家增強版)
更新時間:2010年05月31日 22:49:29 作者:
這篇文章是asp下刪除重復(fù)數(shù)組的函數(shù),已經(jīng)經(jīng)過測試。
因為要寫個東西用到,所以百度了一下,居然有朋友亂寫,而且比較多,都沒有認(rèn)真測試過,只對字符可以,但是對數(shù)字就不可以,而且通用性很差,需要修改才可以真正使用。沒辦法就自己寫了,經(jīng)過測試完全沒有問題,而且思路很方便,代碼很短,如下:
復(fù)制代碼 代碼如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "對不起,參數(shù)1不能為數(shù)組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
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
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end Function
%>
使用方法和函數(shù)表示:
1、cxarraynull(cxstr1,cxstr2)函數(shù)中的兩個參數(shù):
cxstr1:要檢測的數(shù)組變量,可以為空,或其它未知的錯誤數(shù)據(jù),當(dāng)為空或則為錯誤數(shù)據(jù)返回"nodate"。
cxstr2:數(shù)組的分割符號,可以為空,或為chr(13)等,自動替換輸出。
2、測試代碼:
<%
s="1,2,3,4,2,3,5,3"
s=cxarraynull(s,",")
response.write s
%>
輸出:1,2,3,4,5
腳本之家增強版本,解決了數(shù)組中最后一位的,逗號問題。
復(fù)制代碼 代碼如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "對不起,參數(shù)1不能為數(shù)組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
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
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end function
%>
測試代碼:
復(fù)制代碼 代碼如下:
s="1,2,3,4,55,55,55,333,333,2,3,5,3,88,,,,,,,66,,66,,,,,,,,,,,,,,,,,,,,,,,,"
s=cxarraynull(s,",")
response.write s
您可能感興趣的文章:
- 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ù)組轉(zhuǎn)換函數(shù)
- asp.net通過js實現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
- asp textarea 多行數(shù)組分割處理方法
- ASP 過濾數(shù)組重復(fù)數(shù)據(jù)函數(shù)(加強版)
- ASP 使用Filter函數(shù)來檢索數(shù)組的實現(xiàn)代碼
- asp數(shù)組的使用介紹
- Asp與JS的數(shù)組和字符串下標(biāo)介紹
- asp中使用redim、preserve創(chuàng)建動態(tài)數(shù)組實例
- ASP定義數(shù)組方法的技巧
相關(guān)文章
微信開發(fā) 網(wǎng)頁授權(quán)獲取用戶基本信息
這篇文章主要介紹了微信開發(fā) 網(wǎng)頁授權(quán)獲取用戶基本信息的相關(guān)資料,需要的朋友可以參考下2016-09-09P3P 和 跨域 (cross-domain) cookie 訪問(讀取和設(shè)置)
在IE 里面跨域去設(shè)置 cookie跨域的實現(xiàn),嘗試了n中方法都不行,查了一下資料,可以通過設(shè)置header中的p3p值來實現(xiàn),真不錯:)2009-06-06