当前位置:首页 > ASP教程 > ASP其他

asp 数组 重复删除函数(脚本之家增强版)

因为要写个东西用到,所以百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。没办法就自己写了,经过测试完全没有问题,而且思路很方便,代码很短,如下:
代码如下:

<BR /><% <BR />function cxarraynull(cxstr1,cxstr2) <BR />if isarray(cxstr1) then <BR />cxarraynull = "对不起,参数1不能为数组" <BR />Exit Function <BR />end if <BR />if cxstr1 = "" or isempty(cxstr1) then <BR />cxarraynull = "nodate" <BR />Exit Function <BR />end if <BR />ss = split(cxstr1,cxstr2) <BR />cxs = cxstr2&ss(0)&cxstr2 <BR />sss = cxs <BR />for m = 0 to ubound(ss) <BR />cc = cxstr2&ss(m)&cxstr2 <BR />if instr(sss,cc)=0 then <BR />sss = sss&ss(m)&cxstr2 <BR />end if <BR />next <BR />cxarraynull = right(sss,len(sss) - len(cxstr2)) <BR />cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2)) <BR />end Function <BR />%> <BR /> <BR />使用方法和函数表示: <BR />1、cxarraynull(cxstr1,cxstr2)函数中的两个参数: <BR />cxstr1:要检测的数组变量,可以为空,或其它未知的错误数据,当为空或则为错误数据返回"nodate"。 <BR />cxstr2:数组的分割符号,可以为空,或为chr(13)等,自动替换
输出。
2、测试代码:
<%
s="1,2,3,4,2,3,5,3"
s=cxarraynull(s,",")
response.write s
%>
输出:1,2,3,4,5


硕编程增强版本,解决了数组中最后一位的,逗号问题。
代码如下:
<BR /><% <BR />function cxarraynull(cxstr1,cxstr2) <BR />if isarray(cxstr1) then <BR />cxarraynull = "对不起,参数1不能为数组" <BR />Exit Function <BR />end if <BR />if cxstr1 = "" or isempty(cxstr1) then <BR />cxarraynull = "nodate" <BR />Exit Function <BR />end if <BR />do while instr(cxstr1,",,")>0 <BR />cxstr1=replace(cxstr1,",,",",") <BR />loop <BR />if right(cxstr1,1)="," then <BR />cxstr1=left(cxstr1,len(cxstr1)-1) <BR />end if <BR />ss = split(cxstr1,cxstr2) <BR />cxs = cxstr2&ss(0)&cxstr2 <BR />sss = cxs <BR />for m = 0 to ubound(ss) <BR />cc = cxstr2&ss(m)&cxstr2 <BR />if instr(sss,cc)=0 then <BR />sss = sss&ss(m)&cxstr2 <BR />end if <BR />next <BR />cxarraynull = right(sss,len(sss) - len(cxstr2)) <BR />cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2)) <BR />end function <BR />%> <BR /> <BR />测试代码: <BR /><span><U></U></span> 代码如下:
<BR />s="1,2,3,4,55,55,55,333,333,2,3,5,3,88,,,,,,,66,,66,,,,,,,,,,,,,,,,,,,,,,,," <BR />s=cxarraynull(s,",") <BR />response.write s <BR />
            
            


           
                
                                                

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!