ASP 过滤数组重复数据函数(加强版)


Posted in Javascript onMay 31, 2010

函数代码:

<%'******************************************************* 
'过滤数组重复函数名称: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
Javascript 相关文章推荐
一段实时更新的时间代码
Jul 07 Javascript
Javascript学习笔记之 函数篇(三) : 闭包和引用
Nov 23 Javascript
node.js中的favicon.ico请求问题处理
Dec 15 Javascript
JavaScript移除数组内重复元素的方法
Mar 18 Javascript
JavaScript将字符串转换为整数的方法
Apr 14 Javascript
JavaScript中的anchor()方法使用详解
Jun 08 Javascript
Window.Open打开窗体和if嵌套代码
Apr 15 Javascript
AngularJS在IE8的不支持的解决方法
May 13 Javascript
老生常谈jquery id选择器和class选择器的区别
Feb 12 Javascript
vue请求数据的三种方式
Mar 04 Javascript
微信小程序实现电子签名并导出图片
May 27 Javascript
JS实现鼠标移动拖尾
Dec 27 Javascript
javascript 子窗体父窗体相互传值方法
May 31 #Javascript
js post方式传递提交的实现代码
May 31 #Javascript
JS 类型转换常见方法小结
May 31 #Javascript
javascript 传统事件模型构造的事件监听器实现代码
May 31 #Javascript
LazyLoad 延迟加载(按需加载)
May 31 #Javascript
基于jquery的气泡提示效果
May 31 #Javascript
niceTitle 基于jquery的超链接提示插件
May 31 #Javascript
You might like
Wordpress php 分页代码
2009/10/21 PHP
用来解析.htgroup文件的PHP类
2012/09/05 PHP
PHP时间戳 strtotime()使用方法和技巧
2013/10/29 PHP
PHP+MySQL统计该库中每个表的记录数并按递减顺序排列的方法
2016/02/15 PHP
php 防止表单重复提交两种实现方法
2016/11/03 PHP
Laravel框架使用Redis的方法详解
2018/05/30 PHP
微信JSSDK分享功能图文实例详解
2019/04/08 PHP
网站页面自动跳转实现方法PHP、JSP(下)
2010/08/01 Javascript
JavaScript对象学习经验整理
2013/10/12 Javascript
jquery.cookie用法详细解析
2013/12/18 Javascript
js控制分页打印、打印分页示例
2014/02/08 Javascript
jQuery实现级联菜单效果(仿淘宝首页菜单动画)
2014/04/10 Javascript
JavaScript观察者模式(经典)
2015/12/09 Javascript
JavaScipt中栈的实现方法
2016/02/17 Javascript
jQuery实现的兼容性浮动层示例
2016/08/02 Javascript
深入理解Vue transition源码分析
2017/07/30 Javascript
如何使用JavaScript实现栈与队列
2019/06/24 Javascript
微信小程序wx.navigateTo中events属性实现页面间通信传值,数据同步
2019/07/13 Javascript
JS时间戳与日期格式互相转换的简单方法示例
2021/01/30 Javascript
可拖拽组件slider.js使用方法详解
2020/12/04 Javascript
[03:56]显微镜下的DOTA2第十一期——鬼畜的死亡先知播音员
2014/06/23 DOTA
Python下载网络小说实例代码
2018/02/03 Python
Python抓取聚划算商品分析页面获取商品信息并以XML格式保存到本地
2018/02/23 Python
python打造爬虫代理池过程解析
2019/08/15 Python
Python简单实现词云图代码及步骤解析
2020/06/04 Python
Python3爬虫里关于代理的设置总结
2020/07/30 Python
花园仓库建筑:Garden Buildings Direct
2018/02/16 全球购物
SQL Server面试题
2013/04/04 面试题
事业单位个人应聘自荐信
2013/09/21 职场文书
学生发电厂实习自我鉴定
2013/09/22 职场文书
农场厂长岗位职责
2013/12/28 职场文书
公司财务流程之主管工作流程
2014/03/03 职场文书
2014年度党员自我评议
2014/09/13 职场文书
公司租房协议书范本
2014/10/08 职场文书
Nginx同一个域名配置多个项目的实现方法
2021/03/31 Servers
Ubuntu18.04下QT开发Android无法连接设备问题解决实现
2022/06/01 Java/Android