日期:2014-05-16  浏览次数:20862 次

asp 怎么写 对比两个数组 有相同的就清除掉 ?
asp 怎么写 对比两个数组 有相同的就清除掉 ?

列:

arra="15,19,210,22,45,6,55"

arrb="368,111,20,501,22,66,90,55,10"

'比较2个 相同的数字就清除掉 就是把不同的列出 ,区分的格式 用数组也行
'要的结果是: 15,19,210,45,6,368,111,20,501,66,90,10

2个变量里都出现过的话 清除掉


大虾帮忙 ,。
------解决方案--------------------

<%
arra = "15,19,210,22,45,6,55"
arrb = "368,111,20,501,22,66,90,55,10"

arra = Split(arra, ",")
arrb = Split(arrb, ",")
Set dic = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(arra)
If dic.Exists(arra(i)) Then
dic.Remove arra(i)
Else
dic.Add arra(i), arra(i)
End If
Next
For i = 0 To UBound(arrb)
If dic.Exists(arrb(i)) Then
dic.Remove arrb(i)
Else
dic.Add arrb(i), arrb(i)
End If
Next
arr = dic.Items
Set dic = Nothing
Response.Write Join(arr, ",")
%>

------解决方案--------------------
如果只是获得一个字符串结果,hookee 的可以http://bbs.csdn.net/topics/再简短点



<%
dim a,b,ar,d,i
a = "15,19,210,22,45,6,55"
b = "368,111,20,501,22,66,90,55,10"
ar = split(a & "," & b, ",")
set d = CreateObject("Scripting.Dictionary")
For i = 0 to UBound(ar)
    If d.exists(ar(i)) Then
        d.remove ar(i)
    Else
        d.add ar(i), ar(i)
    End If
Next
ar = d.items
set d = nothing
response.write join(ar, ",")
%>


------解决方案--------------------
dim arra,arrb,arr,str,i
arra = "15,19,210,22,45,6,55"
arrb = "368,111,20,501,22,66,90,55,10"

arr  = Split(arra,",") '转成数组
arra = ","&arra&","
str  = ","&arrb&","
For i=0 To UBound(arr)
If InStr(str,","&arr(i)&",")<>0 Then
str = Replace(str,","&arr(i)&",",",")
arra = Replace(arra,","&arr(i)&",",",")
End If
Next
Response.write Replace(arra&str,",,",",") '前后的,自行处理