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
投稿

猜你喜欢

  • python爬取网页版QQ空间,生成各类图表

    2023-01-18 06:30:58
  • Python线程之同步机制实际应用场景举例说明

    2023-06-10 13:57:40
  • eWebEditor不支持IE8的解决方法

    2009-11-02 10:59:00
  • python异步任务队列示例

    2021-05-04 03:09:07
  • 用Python创建简易网站图文教程

    2023-03-09 20:37:57
  • python3中编码获取网页的实例方法

    2023-07-17 23:31:47
  • Python模拟登录网易云音乐并自动签到

    2023-05-28 03:10:05
  • python小程序之4名牌手洗牌发牌问题解析

    2023-08-28 04:06:20
  • Prometheus的安装和配置教程详解

    2023-03-16 21:38:43
  • MYSQL和ORACLE的一些操作区别

    2008-12-18 14:33:00
  • MySQL中的 Binlog 深度解析及使用详情

    2024-01-19 04:15:48
  • 软件测试之使用Fiddler实现弱网测试

    2023-03-04 20:47:45
  • 基于matplotlib xticks用法详解

    2022-10-09 12:51:31
  • Access为后台数据库的网站统计系统

    2008-11-16 17:34:00
  • mysql8.0.11客户端无法登陆的解决方法

    2024-01-17 18:57:52
  • Microsoft Office Access 2007使用技巧

    2008-05-23 13:23:00
  • 提升Python运行速度的5个小技巧

    2021-07-28 20:25:24
  • Python 第一步 hello world

    2021-03-25 06:42:15
  • Python二进制串转换为通用字符串的方法

    2022-09-30 19:36:11
  • Next.js应用转换为TypeScript方法demo

    2024-05-11 09:36:17
  • asp之家 网络编程 m.aspxhome.com