asp 数组 重复删除函数代码
来源:脚本之家 发布时间:2011-03-03 10:47:00
因为要写个东西用到,所以百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。没办法就自己写了,经过测试完全没有问题,而且思路很方便,代码很短,如下:
代码如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "对不起,参数1不能为数组"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
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
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end Function
%>
使用方法和函数表示:
1、cxarraynull(cxstr1,cxstr2)函数中的两个参数:
cxstr1:要检测的数组变量,可以为空,或其它未知的错误数据,当为空或则为错误数据返回"nodate"。
cxstr2:数组的分割符号,可以为空,或为chr(13)等,自动替换输出。
2、测试代码:
<%
s="1,2,3,4,2,3,5,3"
s=cxarraynull(s,",")
response.write s
%>
输出:1,2,3,4,5
脚本之家增强版本,解决了数组中最后一位的,逗号问题。
代码如下:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "对不起,参数1不能为数组"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
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
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end function
%>
测试代码:
代码如下:
s="1,2,3,4,55,55,55,333,333,2,3,5,3,88,,,,,,,66,,66,,,,,,,,,,,,,,,,,,,,,,,,"
s=cxarraynull(s,",")
response.write s
猜你喜欢
- 判断访问是否来自搜索引擎的函数,有兴趣的可以试试! <% '检查当前用户是否是蜘蛛人 Function check(
- 很多现代的浏览器在地址栏的右边有个搜索框,默认的安装有 Google 搜索等。如下图所示:其实这是 OpenSearch 的一个应用,只要编
- 我们可以利用 Cookie collection 来刪除客户端的Cookies: <%
- 请问论坛的树状记录表是怎么展开的?如何做?论坛的这种展开技术一般采用两种方法实现,一种是采用递归的方法,优点是逻辑简单,编程简单,缺点是速度
- SQL的扩展的删除与恢复 删除 代码如下:use master exec spdropextendedproc “xpcmdshell“ e
- 雅虎的BrowserPlus在曝光了N久后终于发布了,一款类似于Google Gears的浏览器增强插件。在支持的操作系统方面,Gears明
- Q: I am working with Oracle database 8.1.7 and I have written a JAVA c
- 自定义数据库自动编号初始值和步进值问题: 如何定义数据库的自动编号字段的初始值和步进值?如何定义自动增加字段的初始值和步进值?如何使删除过数
- Web性能优化最佳实践中最重要的一条是减少HTTP请求,它也是YSlow中比重最大的一条规则。减少HTTP请求的方案主要有合并JavaScr
- 表的故障检测和修正的一般过程如下:◆ 检查出错的表。如果该表检查通过,则完成任务,否则必须修复出错的数据库表。◆ 在开始修复之前对表文件进行
- 美化主要表现在鼠标放到菜单上后(即鼠标悬停)的效果,这里首先介绍几个经常用到的CSS属性:backgr
- 代码如下: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%&
- 一个封装好的JavaScript拖动类,使用方便:<div id="idDrag" style="bor
- 我们工作中经常需要将数据转化成柱状图,饼图等,以方便直观的分析数据, 这里给大家介绍一个ASP中制作饼图、柱状图的组件:csDra
- 在上一篇《服务器XMLHTTP(Server XMLHTTP in ASP)基础》中我介绍了一下ServerX
- 下面就是我们的authenticate.asp页面,在这里,将用户的信息收集起来,连同最初的URL一起传到一个识别用户身份的页面中。我们可用
- 第一类工厂相当于mootools的Native方法,用于创建一些具有扩展能力的类,但这些类并没有继承能力,此类工厂也不能以某个类作为蓝本创建
- 有的时候,我们为了保持网页的美观,需要将较长的文字在一定长度时截断。比如我们希望在列表中显示文章标题的前15个字,那么一个这样的标题:“rs
- 机器A: select instance_name from v$instance; select name from v$database
- 表单在提交前我们通常会用客户端JS对其内容进行验证,通常都是写一个函数然后在onsumbit事件中调用,如下:<html><