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 相关文章推荐
List the Codec Files on a Computer
Jun 11 Javascript
理解Javascript_11_constructor实现原理
Oct 18 Javascript
中文路径导致unitpngfix.js不正常的解决方法
Jun 26 Javascript
基于jQuery Ajax实现上传文件
Mar 24 Javascript
jquery css实现邮箱自动补全
Nov 14 Javascript
js生成随机数方法和实例
Jan 17 Javascript
React-Native之定时器Timer的实现代码
Oct 04 Javascript
JavaScript数据结构之单链表和循环链表
Nov 28 Javascript
js回文数的4种判断方法示例
Jun 04 Javascript
利用JS代码自动删除稿件的普通弹幕功能
Sep 20 Javascript
Node如何后台数据库使用增删改查功能
Nov 21 Javascript
详解如何使用Node.js实现热重载页面
May 06 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支持页面回退的两种方法
2008/01/10 PHP
使用PHP提取视频网站页面中的FLASH地址的代码
2010/04/17 PHP
php使用Image Magick将PDF文件转换为JPG文件的方法
2015/04/01 PHP
PHP递归创建多级目录
2015/11/05 PHP
JQuery扩展插件Validate—4设置错误提示的样式
2011/09/05 Javascript
javascrip关于继承的小例子
2013/05/10 Javascript
简单实用jquery版三级联动select示例
2013/07/04 Javascript
jQuery通过扩展实现抖动效果的方法
2015/03/11 Javascript
JQuery 的跨域方法推荐_可跨任何网站
2016/05/18 Javascript
Vue.js表单控件实践
2016/10/27 Javascript
JS设计模式之观察者模式实现实时改变页面中金额数的方法
2018/02/05 Javascript
Vuejs 单文件组件实例详解
2018/02/09 Javascript
VUE中v-on:click事件中获取当前dom元素的代码
2018/08/22 Javascript
详解Vue项目引入CreateJS的方法(亲测可用)
2019/05/30 Javascript
python简单判断序列是否为空的方法
2015/06/30 Python
轻松掌握python设计模式之策略模式
2016/11/18 Python
浅谈numpy数组中冒号和负号的含义
2018/04/18 Python
Python selenium抓取微博内容的示例代码
2018/05/17 Python
pyspark操作MongoDB的方法步骤
2019/01/04 Python
python批量将excel内容进行翻译写入功能
2019/10/10 Python
tensorflow安装成功import tensorflow 出现问题
2020/04/16 Python
PyCharm 2020.2下配置Anaconda环境的方法步骤
2020/09/23 Python
详解使用postMessage解决iframe跨域通信问题
2019/11/01 HTML / CSS
德国传统玻璃制造商:Cristalica
2018/04/23 全球购物
百度JavaScript笔试题
2015/01/15 面试题
优秀团员个人的自我评价
2013/10/02 职场文书
售后主管岗位职责
2013/12/08 职场文书
《问银河》教学反思
2014/02/19 职场文书
领导班子三严三实对照检查材料
2014/09/25 职场文书
公司授权委托书
2014/10/17 职场文书
2014年数学教师工作总结
2014/12/03 职场文书
2016年中秋节慰问信
2015/12/01 职场文书
利用python做表格数据处理
2021/04/13 Python
Pytorch DataLoader shuffle验证方式
2021/06/02 Python
php png失真的原因及解决办法
2021/11/17 PHP
sql server 累计求和实现代码
2022/02/28 SQL Server