ASP函数过滤数组重复数据代码

来源:asp之家 时间:2010-01-02 20:36:00 

很实用的过滤重复数据的asp代码,函数如下:

<%'*******************************************************
'过滤数组重复函数名称: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 


 

标签:函数,重复数据,数组,asp
0
投稿

猜你喜欢

  • 用Assets 面板为你的站点定做颜色

    2007-02-03 11:39:00
  • 实现UTF8转换GB2312国标码的asp代码

    2011-02-28 10:53:00
  • Flash对象在(x)HTML中的格式和参数及安全性

    2010-04-01 11:55:00
  • IE及Opera浏览器兼容笔记

    2008-08-21 17:53:00
  • SQL Server密码管理的六个危险判断

    2008-10-23 13:57:00
  • CSS pointer-events下层元素被点击

    2010-04-11 22:31:00
  • 2008农历新年各大网站Logo秀

    2008-02-11 16:33:00
  • 巧用Dreamweaver MX制作阴影字

    2009-08-31 17:36:00
  • MySQL数据库中修改密码及访问限制设置详解

    2009-09-01 14:19:00
  • 教你快速掌握如何向MySQL的表中录入数据

    2008-11-27 16:45:00
  • XML教程—编写结构完整的XML文档

    2008-10-11 13:43:00
  • opera img onload重复执行

    2008-01-17 12:01:00
  • Oracle row_number() over()解析函数高效实现分页

    2011-12-01 10:33:07
  • 三个动画函数,透明度渐变、位置移动、尺寸变化javascript源码

    2010-03-28 13:23:00
  • FileSystem对象常用的文件操作函数有哪些?

    2009-11-01 15:11:00
  • sqlserver 数据库连接字符串中的可选项收集

    2011-10-24 19:48:37
  • 一个较新的ASP后门服务端实现代码

    2011-02-16 10:41:00
  • Microsoft SQL Server数据库开发问题详解

    2009-10-23 14:16:00
  • 个人网站与动网整合非官方方法

    2009-07-05 18:42:00
  • MySQL的root帐户密码重置方法

    2007-08-24 15:53:00
  • asp之家 网络编程 m.aspxhome.com