国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

ASP 過濾數組重復數據函數(加強版)

2019-11-21 00:27:40
字體:
來源:轉載
供稿:網友
函數代碼:
復制代碼 代碼如下:

<%'*******************************************************
'過濾數組重復函數名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數組下標時返回最后.
'使用于二維數組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數3類型必需為數字"
Exit Function
end if
else
array_no = "對不起,參數3類型必需為數字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數1不能為數組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
array_no = "沒有數據"
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 "字串為數字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數組時:"&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
字串為數字時:1,2,3,11,22,33,12,13,14,333
字串為空時:沒有數據
字串為混合時:sdf,abc,12,2
字串為數組時:對不起,參數1不能為數組
字串為未知變量時:沒有數據
提取某一位時,沒有超過下標時:bb
提取某一位時,超過下標時:edc


武林網增強版本: 解決了數組常見錯誤
復制代碼 代碼如下:

<%
'*******************************************************
'過濾數組重復函數名稱:array_no(cxstr1,cxstr2,cxstr3)
'cxstr1:任意的字符串,自動識別
'cxstr2:cxstr1中分割符號。
'cxstr3:提取結果中的某一位置字串,等于0時返回為全部,大于數組下標時返回最后.
'使用于二維數組
'*******************************************************
function array_no(cxstr1,cxstr2,cxstr3)
if len(cxstr3) > 0 then
if not IsNumeric(cxstr3) then
array_no = "對不起,參數3類型必需為數字"
Exit Function
end if
else
array_no = "對不起,參數3類型必需為數字"
Exit Function
end if
if isarray(cxstr1) then
array_no = "對不起,參數1不能為數組"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
array_no = "沒有數據"
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 "字串為數字時:"&array_no(s2,",",0)&"<br>"
response.write "字串為空時:"&array_no(s3,",",0)&"<br>"
response.write "字串為混合時:"&array_no(s4,",",0)&"<br>"
response.write "字串為數組時:"&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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昌图县| 海兴县| 乐都县| 攀枝花市| 漳州市| 杨浦区| 界首市| 天等县| 常宁市| 威远县| 柳江县| 香港| 娄烦县| 佳木斯市| 太仓市| 新闻| 鄱阳县| 遵义县| 泰宁县| 蒙山县| 密山市| 惠东县| 荔波县| 安丘市| 武陟县| 揭东县| 攀枝花市| 渝北区| 安溪县| 大埔区| 武隆县| 游戏| 卫辉市| 青冈县| 湘阴县| 岢岚县| 关岭| 寿阳县| 乌鲁木齐市| 资中县| 永泰县|