您现在的位置是:网站首页> 编程资料编程资料
asp 数组 重复删除函数(增强版)_应用技巧_
2023-05-25
330人已围观
简介 asp 数组 重复删除函数(增强版)_应用技巧_
因为要写个东西用到,所以百度了一下,居然有朋友乱写,而且比较多,都没有认真测试过,只对字符可以,但是对数字就不可以,而且通用性很差,需要修改才可以真正使用。没办法就自己写了,经过测试完全没有问题,而且思路很方便,代码很短,如下:
复制代码 代码如下:
<%
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取得数组中的最大值的方法
- asp下使用数组存放数据的代码
- asp 得到动态数组中元素的个数
- asp.net 数组中字符串替换的几种方式
- asp 动态数组 提供Add、Insert、Remove、RemoveAt、Search等方法。
- asp.net 字符串、二进制、编码数组转换函数
- asp.net通过js实现Cookie创建以及清除Cookie数组的代码
- asp textarea 多行数组分割处理方法
- ASP 过滤数组重复数据函数(加强版)
- ASP 使用Filter函数来检索数组的实现代码
- asp数组的使用介绍
- Asp与JS的数组和字符串下标介绍
- asp中使用redim、preserve创建动态数组实例
- ASP定义数组方法的技巧
相关内容
- ASP trim,ltrim,rtrim 去前后空格 函数_ASP基础_
- ASP 支持中文的len(),left(),right()的函数代码_应用技巧_
- asp 去除最后一个逗号为空字符串的代码_应用技巧_
- asp textarea 多行数组分割处理方法_应用技巧_
- access改mdb为asp所带来的灾难 附mdb防下载方法_应用技巧_
- asp IsValidEmail 验证邮箱地址函数(email)_应用技巧_
- asp下过滤非法的SQL字符的函数代码_应用技巧_
- ASP URL反编码函数代码_应用技巧_
- asp 删除数据并同时删除图片的代码_应用技巧_
- 实现UTF8转换GB2312国标码的asp代码_应用技巧_
