asp怎么移除数组中某个项目
1个回答
展开全部
<%
'一个删除数组内元素的函数
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的值时,就不组进数组里。
'一个删除数组内元素的函数
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的值时,就不组进数组里。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询