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 相关文章推荐
Firefox中autocomplete=&quot;off&quot; 设置不起作用Bug的解决方法
Mar 25 Javascript
jquery $.fn $.fx是什么意思有什么用
Nov 04 Javascript
原生javaScript做得动态表格(注释写的很清楚)
Dec 29 Javascript
JavaScript插件化开发教程(六)
Feb 01 Javascript
jQuery编程中的一些核心方法简介
Aug 14 Javascript
Javascript实现的简单右键菜单类
Sep 23 Javascript
html5+javascript实现简单上传的注意细节
Apr 18 Javascript
JavaScript必看小技巧(必看)
Jun 07 Javascript
微信小程序 教程之WXML
Oct 18 Javascript
jQuery源码分析之init的详细介绍
Feb 13 Javascript
微信小程序使用echarts获取数据并生成折线图
Oct 16 Javascript
node koa2 ssr项目搭建的方法步骤
Dec 11 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笔记之常用文件操作
2010/10/12 PHP
免费手机号码归属地API查询接口和PHP使用实例分享
2014/04/10 PHP
PHP多个文件上传到服务器实例
2014/10/29 PHP
php运行提示:Fatal error Allowed memory size内存不足的解决方法
2014/12/17 PHP
微信公众号支付之坑:调用支付jsapi缺少参数 timeStamp等错误解决方法
2016/01/12 PHP
php 调用ffmpeg获取视频信息的简单实现
2017/04/03 PHP
php json转换相关知识(小结)
2018/12/21 PHP
jquery 1.4.2发布!主要是性能与API
2010/02/25 Javascript
选择复选框按钮置灰否则按钮可用
2014/05/22 Javascript
wap图片滚动特效无css3元素纯js脚本编写
2014/08/22 Javascript
jquery单行文字向上滚动效果的实现代码
2014/09/05 Javascript
JS绘制微信小程序画布时钟
2016/12/24 Javascript
js中setTimeout的妙用--防止循环超时
2017/03/06 Javascript
js实现一键复制功能
2017/03/16 Javascript
js实现canvas保存图片为png格式并下载到本地的方法
2017/08/31 Javascript
初探JavaScript 面向对象(推荐)
2017/09/03 Javascript
JQuery扩展对象方法操作示例
2018/08/21 jQuery
Vue CLI4 Vue.config.js标准配置(最全注释)
2020/06/05 Javascript
在Python中使用SimpleParse模块进行解析的教程
2015/04/11 Python
Python常用小技巧总结
2015/06/01 Python
Django中对通过测试的用户进行限制访问的方法
2015/07/23 Python
python数据类型判断type与isinstance的区别实例解析
2017/10/31 Python
Python OpenCV读取png图像转成jpg图像存储的方法
2018/10/28 Python
Python使用修饰器进行异常日志记录操作示例
2019/03/19 Python
CSS3弹性伸缩布局之box布局
2016/07/12 HTML / CSS
CSS3 实现飘动的云朵动画
2020/12/01 HTML / CSS
详解HTML5中CSS外观属性
2020/09/10 HTML / CSS
BookOutlet加拿大:在网上书店购买廉价折扣图书和小说
2018/10/05 全球购物
英国景点门票网站:attractiontix
2019/08/27 全球购物
美国名牌手表折扣网站:Jomashop
2020/05/22 全球购物
Tea Collection官网:一家位于旧金山的童装公司
2020/08/07 全球购物
如何提高SQL Server的安全性
2016/07/25 面试题
银行毕业实习自我鉴定
2013/09/19 职场文书
导游词之青城山景区
2019/09/27 职场文书
关于Python使用turtle库画任意图的问题
2022/04/01 Python
Win11 KB5015814遇安装失败 影响开始菜单性能解决方法
2022/07/15 数码科技