网络编程
位置:首页>> 网络编程>> Asp编程>> ASP函数过滤数组中重复数据方法

ASP函数过滤数组中重复数据方法

 来源:asp之家 发布时间:2010-01-02 20:32:00 

标签:函数,重复数据,数组,asp

因为要用到过滤一组中重复的数据,使之变成没有重复的一组数据的功能,百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。

没办法就自己写了,经过测试完全没有问题,而且思路很方便,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" 
cxarraynull(s,",")
%> 

输出:1,2,3,4,5

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com