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 相关文章推荐
js函数调用常用方法详解
Dec 03 Javascript
文字不间断滚动(上下左右)实例代码
Apr 21 Javascript
Javascript中匿名函数的调用与写法实例详解(多种)
Jan 26 Javascript
JavaScript中通过提示框跳转页面的方法
Feb 14 Javascript
省市联动效果的简单实现代码(推荐)
Jun 06 Javascript
switch语句的妙用(必看篇)
Oct 03 Javascript
Angular路由简单学习
Dec 26 Javascript
解决webpack+Vue引入iView找不到字体文件的问题
Sep 28 Javascript
Vue列表渲染的示例代码
Nov 01 Javascript
React精髓!一篇全概括小结(急速)
May 23 Javascript
JavaScript设计模式---单例模式详解【四种基本形式】
May 16 Javascript
weui上传多图片,压缩,base64编码的示例代码
Jun 22 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
php strtotime 函数UNIX时间戳
2009/01/14 PHP
用sql命令修改数据表中的一个字段为非空(not null)的语句
2010/06/04 PHP
php实现无限级分类实现代码(递归方法)
2011/01/01 PHP
PHP sprintf() 函数的应用(定义和用法)
2012/06/29 PHP
php判断页面是否是微信打开的示例(微信打开网页)
2014/04/25 PHP
Yii使用ajax验证显示错误messagebox的解决方法
2014/12/03 PHP
php实现的中文分词类完整实例
2017/02/06 PHP
PHP针对伪静态的注入总结【附asp与Python相关代码】
2017/08/01 PHP
javascript:void(0)的真正含义实例分析
2008/08/20 Javascript
jQuery EasyUI 中文API Button使用实例
2010/04/14 Javascript
jquery图片播放浏览插件prettyPhoto使用详解
2014/12/19 Javascript
Web 开发中Ajax的Session 超时处理方法
2017/01/19 Javascript
jQuery快速高效制作网页交互特效
2017/02/24 Javascript
jQuery简易时光轴实现方法示例
2017/03/13 Javascript
使用Xcache缓存器加速PHP网站的配置方法
2017/04/22 Javascript
JS正则表达式验证中文字符
2017/05/08 Javascript
基于Vue插入视频的2种方法小结
2019/04/02 Javascript
Nodejs 识别图片类型的方法
2019/08/15 NodeJs
详解vue页面首次加载缓慢原因及解决方案
2019/11/06 Javascript
JavaScript队列结构Queue实现过程解析
2020/03/07 Javascript
vue 重塑数组之修改数组指定index的值操作
2020/08/09 Javascript
[01:06]欢迎来到上海,TI9
2018/08/26 DOTA
Win10下python3.5和python2.7环境变量配置教程
2018/09/18 Python
如何用Python 实现全连接神经网络(Multi-layer Perceptron)
2020/10/15 Python
HTML5 Canvas入门学习教程
2016/03/17 HTML / CSS
HTML5 textarea高度自适应的两种方案
2020/04/08 HTML / CSS
巴西女装购物网站:Eclectic
2018/04/24 全球购物
机械专业应届生求职信
2013/12/12 职场文书
捐书寄语赠言
2014/01/18 职场文书
授权委托书格式模板
2014/04/03 职场文书
护士工作失误检讨书
2014/09/14 职场文书
毕业论文致谢词
2015/05/14 职场文书
2015小学音乐教师个人工作总结
2015/07/21 职场文书
保外就医申请书范文
2015/08/06 职场文书
小学生反邪教心得体会
2016/01/15 职场文书
《中国机长》观后感:敬畏生命,敬畏职责
2019/11/12 职场文书