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 



 

标签:asp,数组,重复
0
投稿

猜你喜欢

  • Oracle 游标使用总结

    2009-10-02 17:36:00
  • 转换字符串单词的第一个字母为大写

    2007-10-18 10:50:00
  • ASP同一站点不同编码程序出现乱码解决办法

    2008-11-10 12:08:00
  • 合并SQL脚本文件的方法分享

    2011-09-30 11:13:03
  • 如何改良你的CSS代码编写结构

    2008-09-29 16:03:00
  • asp如何制作一个弹出式的调查窗口?

    2010-06-29 21:24:00
  • 多按钮共存——don’t make me think

    2010-01-11 20:20:00
  • 我的“Orcas初览”讲座

    2007-09-23 12:53:00
  • Select下拉列表控件美化

    2008-11-12 12:55:00
  • SQL查询效率:100w数据查询只需要1秒钟

    2008-12-09 14:36:00
  • 两段不错的JS文字特效

    2007-09-27 12:52:00
  • 数据库大战: MS SQL Server & IBM DB2

    2009-08-25 16:24:00
  • 设计师如何更有效拿到结果?

    2008-09-22 20:30:00
  • ASP JSON类源码

    2011-04-30 16:38:00
  • PS中执行N遍选定动作的脚本

    2008-02-22 21:33:00
  • 向MySQL数据库的表中录入数据的实用方法

    2008-12-17 16:24:00
  • Oracle 自增(auto increment) 或 标识字段的建立方法

    2009-03-06 11:15:00
  • MySql常用命令总结

    2009-09-16 10:51:00
  • Ajax缓存和编码问题的最终解决方案

    2010-03-30 13:42:00
  • 如何由Sybase向SQL Server移植数据库

    2009-01-20 15:56:00
  • asp之家 网络编程 m.aspxhome.com