stra="123,A|234,B|455,C|567,D "
arrya=split(stra,"|")
stra=""
delstr="455,C"
for i=0 to ubound(arrya)
if arrya(i)<>delstr then
if stra<>"" then
stra=stra & "|" & arrya(i)
else
stra=arrya(i)
end if
end if
next
上边的是删除等于指定值的一组,当然也可以指定删除第一个元素(注:第一个的下标是0 第n个下标是n-1)
stra="123,A|234,B|455,C|567,D "
arrya=split(stra,"|")
stra=""
delid=2
for i=0 to ubound(arrya)
if i<>delid-1 then
if stra<>"" then
stra=stra & "|" & arrya(i)
else
stra=arrya(i)
end if
end if
next
<%
'一个删除数组内元素的函数
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)
'用法
n1 = "a,b,1,11,12,13,14,15,16,17,19,20,22"
n2 = "a,1"
response.write mover(n1,n2)
'结果是b,11,12,13,14,15,16,17,19,20,22
%>
原理:Split分隔逗号得出数组后,循环,跟N2同理,
循环再组装数组,值等于N2的值时,就不组进数组里。
x=rs("x") 'x为数组参数
y="一元素"
z=replace(x,y,"") '新数组