asp数组重复删除函数
因为要写个东西用到,所以百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。没办法就自己写了,经过测试完全没有问题,而且思路很方便,代码很短,如下:
复制代码 代码如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "对不起,参数1不能为数组"
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
%>
使用方法和函数表示:
1、cxarraynull(cxstr1,cxstr2)函数中的.两个参数:
cxstr1:要检测的数组变量,可以为空,或其它未知的错误数据,当为空或则为错误数据返回"nodate"。
cxstr2:数组的分割符号,可以为空,或为chr(13)等,自动替换输出。
2、测试代码:
<%
s="1,2,3,4,2,3,5,3"
s=cxarraynull(s,",")
e s
%>
输出:1,2,3,4,5
增强版本,解决了数组中最后一位的,逗号问题。
复制代码 代码如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "对不起,参数1不能为数组"
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
%>
测试代码:
复制代码 代码如下:
s="1,2,3,4,55,55,55,333,333,2,3,5,3,88,,,,,,,66,,66,,,,,,,,,,,,,,,,,,,,,,,,"
s=cxarraynull(s,",")
e s
-
SQL的SUBSTR 函数的使用方法介绍
SUBSTR函数是用来截取数据库某一列字段中的一部分。在各个数据库的函数名称不一样(真是蛋疼,后发明的`数据库难道不能同先发明的一样吗?)复制代码代码如下:MySQL:SUBSTR(),SUBSTRING()Oracle:SUBSTR()SQLServer:SUBSTRING();常用的方式是:SBUSTR(str,pos);就是从pos...
-
讲解HTML中iframe和frame的区别
不知道你在项目中用过frameset属性没有,frameset这个属性是在去年我在一个在线客服系统制作中用过,因为客服系统要有固定的布局,上面一块,下面一块等等,当时就是用的frameset和frame。在我用完了这些属性之后,我才明白了iframe和frame的`区别。因为在这之前,我项目中...
-
怎么使用Javascript获取距今n天前的日期
复制代码代码如下:functionTest(day){vartoday=newDate();varbeforMilliseconds=ime()-1000*3600*24*day;varbeforday=newDate();ime(beforMilliseconds);varstrYear=ullYear();varstrDay=ate();varstrMonth=onth()+1;if(strMonth<10){strMonth="0"+strMonth;}...
-
如何理解Javascript的caller,callee,call,apply区别
在提到上述的概念之前,首先想说说javascript中函数的隐含参数:argumentsarguments该对象代表正在执行的函数和调用它的函数的参数。[function.]arguments[n]参数function:选项。当前正在执行的Function对象的名字。n:选项。要传递给Function对象的从0开始的参数值...