asp 数组 重复删除函数(脚本之家增强版)

所属分类: 网络编程 / ASP编程 阅读数: 1788
收藏 0 赞 0 分享

因为要写个东西用到,所以百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。没办法就自己写了,经过测试完全没有问题,而且思路很方便,代码很短,如下:

复制代码 代码如下:

<%
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

更多精彩内容其他人还在看

asp知识整理笔记4(问答模式)

这是关于asp知识整理的最后一份笔记,希望大家仔细阅读。
收藏 0 赞 0 分享

ASP基础知识VBScript基本元素讲解

这篇文章主要介绍了ASP基础知识VBScript基本元素的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

ASP编码和解码函数详解

这篇文章主要介绍了ASP编码和解码函数的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

ASP显示页面执行时间的方法

这篇文章主要介绍了ASP显示页面执行时间的方法,在本地测试一下输出页面需要多少时间,需要的朋友可以参考下
收藏 0 赞 0 分享

ASP基础入门第一篇(ASP技术简介)

本文将以 Active Server Pages 为中心,向你全面展示制作动态商业网站的步骤和技巧并通过大量的实例,让你在不断的理论和实践之中笑傲“网络”……
收藏 0 赞 0 分享

ASP基础入门第二篇(ASP基础知识)

这篇文章是ASP基础入门第二篇,第一篇展示了ASP动态网站设计的一些最基本的方法,相信通过实践各位对 ASP 已经有了最基本的了解,本文将进一步介绍ASP动态网站的一些基本技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

ASP基础入门第三篇(ASP脚本基础)

通过前两篇的学习,相信各位已经对 ASP 的动态网站设计有了一个基本的概念和整体的印象。从本篇开始作者将从脚本语言的使用着手,由浅入深地带领大家探索 ASP 动态网站设计的真正奥秘。
收藏 0 赞 0 分享

ASP基础入门第四篇(脚本变量、函数、过程和条件语句)

大家在学习了脚本语言 VBScript 的变量、常量和过程的基本概念后,本期将继续向各位介绍 VBScript 的函数和语法。
收藏 0 赞 0 分享

ASP基础入门第五篇(ASP脚本循环语句)

在本文上两篇中,我们学习了脚本语言 VBScript 的变量、函数、过程和条件语句,本篇将继续给大家介绍 VBScipt 的循环语句,并对脚本语言在 ASP 中的应用加以总结。  
收藏 0 赞 0 分享

ASP基础入门第六篇(ASP内建对象Request)

从本篇开始作者从 ASP 内建对象着手,为大家详细剖析 ASP 的六个内建对象和各种组件的特性和方法,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多