威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
ASP教程>> ASP基础 应用技巧 数据库相关 ASP类 存储过程 FSO专栏 ASP其他
当前位置:首页 > ASP教程 > 应用技巧
上一节 下一节
 asp下去除数组中重复项的方法

复制代码 代码如下:

<%
function mover(rstr)
dim i,spstr
spstr = split(rstr,",")
for i = 0 to ubound(spstr)
if i = 0 then
mover = mover & spstr(i) & ","
else
if instr(mover,spstr(i))=0 and i=ubound(spstr) then
mover = mover & spstr(i)
elseif instr(mover,spstr(i))=0 then
mover = mover & spstr(i) & ","
end if
end if
next
end function
response.write mover("abc,abc,dge,gcg,dge,gcg,die,dir,die")%>

结果是:abc,dge,gcg,die,dir

如果是两个数组进行对比,去掉相同的数组元素:

复制代码 代码如下:

<%
        function mover(farray,sarray)
        a = split(farray, ",")
            set dic = createobject("scripting.dictionary")
            for k=0 to ubound(a)
             if a(k)<> "" then dic.add "_" & a(k), a(k)
            next
            a = split(sarray, ",")
            for k=0 to ubound(a)
                if a(k)<> "" then
                    if dic.exists("_" & a(k)) then
                    dic.remove "_" & a(k)
                    end if
                end if
            next
            items = dic.items()
            set dic = nothing
            mover=join(items, ",")
        end function
n1 = "a,b,1,11,12,13,14,15,16,17,19,20,22"
n2 = "a,1,12,14,18,19,20"
response.write mover(n1,n2)
%>

结果是:

3.数组a中有为空的元素(如a=array("ww","ss","","dd","","ee")),
 想把这些空元素从数组a中去掉.并把去掉空元素有的数组赋给数组b.

复制代码 代码如下:

 str=""
for i = lbound(a) to ubound(a)
if a(i)<>"" then
if i<>lbound(a) then str = str + "," end if
str = str & a(i)
end if
next
b = split(str,",")


申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
ASP基础
应用技巧
数据库相关
ASP类
存储过程
FSO专栏
ASP其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821