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 相关文章推荐
jquerymobile checkbox及时刷新才能获取其准确值
Apr 14 Javascript
jQuery.buildFragment使用方法及思路分析
Jan 07 Javascript
jQuery操作checkbox选择(list/table)
Apr 07 Javascript
不要使用jQuery触发原生事件的方法
Mar 03 Javascript
jQuery实现鼠标经过事件的延时处理效果
Aug 20 Javascript
使用CDN和AJAX加速WordPress中jQuery的加载
Dec 05 Javascript
微信和qq时间格式模板实例详解
Oct 21 Javascript
JS生成一维码(条形码)功能示例
Jan 19 Javascript
JavaScript中 ES6变量的结构赋值
Jul 10 Javascript
p5.js码绘“跳动的小正方形”的实现代码
Oct 22 Javascript
Layui实现主窗口和Iframe层参数传递
Nov 14 Javascript
微信小程序录音实现功能并上传(使用node解析接收)
Feb 26 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学习之正则表达式
2011/04/17 PHP
php使用Jpgraph创建柱状图展示年度收支表效果示例
2017/02/15 PHP
PHP 实现公历日期与农历日期的互转换
2017/09/13 PHP
PHP 访问数据库配置通用方法(json)
2018/05/20 PHP
在 Laravel 中动态隐藏 API 字段的方法
2019/10/25 PHP
jquery ajax提交表单数据的两种方式
2009/11/24 Javascript
juqery 学习之四 筛选查找
2010/11/30 Javascript
javascript判断ie浏览器6/7版本加载不同样式表的实现代码
2011/12/26 Javascript
js数组去重的常用方法总结
2014/01/24 Javascript
node.js超时timeout详解
2014/11/26 Javascript
jquery实现全选功能效果的实现代码
2016/05/05 Javascript
移动端使用localStorage缓存Js和css文的方法(web开发)
2016/09/20 Javascript
nodejs个人博客开发第七步 后台登陆
2017/04/12 NodeJs
JavaScript之iterable_动力节点Java学院整理
2017/06/29 Javascript
详解vue.js+UEditor集成 [前后端分离项目]
2017/07/07 Javascript
Vue.js简易安装和快速入门(第二课)
2017/10/17 Javascript
echarts学习笔记之图表自适应问题详解
2017/11/22 Javascript
[01:22:28]DOTA2-DPC中国联赛 正赛 SAG vs RNG BO3 第一场 1月18日
2021/03/11 DOTA
TensorFlow实现MLP多层感知机模型
2018/03/09 Python
python GUI实现小球满屏乱跑效果
2019/05/09 Python
Django框架之登录后自定义跳转页面的实现方法
2019/07/18 Python
基于Python中random.sample()的替代方案
2020/05/23 Python
OpenCV利用python来实现图像的直方图均衡化
2020/10/21 Python
地图可视化神器kepler.gl python接口的使用方法
2020/12/22 Python
HTML5之消息通知的使用(Web Notification)
2018/10/30 HTML / CSS
J2EE面试题集锦(附答案)
2013/08/16 面试题
电子商务专业毕业生工作推荐信
2013/11/17 职场文书
幼儿园大班开学教师寄语
2014/04/03 职场文书
公司委托书怎么写
2014/08/02 职场文书
2014年幼儿园教研工作总结
2014/12/04 职场文书
实习证明模板
2015/06/16 职场文书
教研活动主持词
2015/07/03 职场文书
2016年教师师德师风承诺书
2016/03/25 职场文书
Redis模仿手机验证码发送的实现示例
2021/11/02 Redis
InterProcessMutex实现zookeeper分布式锁原理
2022/03/21 Java/Android
Python pyecharts案例超市4年数据可视化分析
2022/08/14 Python