如何将两个数组进行合并?同样的元素只保留一个。
如题
------解决方案--------------------dim a,b,c,d,e,arr1
dim arr()
dim i,j,k
dim flag
redim arr(0)
flag= "false "
a=array(2,2,3,4,5,1,8)
b=array(1,6,4,7,9,0,7)
c=join(a, ", ")
d=join(b, ", ")
e=c& ", "&d
arr1=split(e, ", ")
k=0
for i=0 to ubound(arr1)
for j=0 to ubound(arr)
if arr1(i)=arr(j) then '如果出现相同元素,则flag= "false ",跳出内部循环
flag= "false "
exit for
else
flag= "true "
end if
next
if flag= "true " then '如果一个内部循环完毕flag= "true ",则将arr1中的元素写入arr,变成其一个新的元素
redim preserve arr(k)
arr(k)=arr1(i)
k=k+1
end if
next
for i=0 to ubound(arr) '循环输出新数组元素
Response.Write arr(i)& " <br> "
next
结果:
2
3
4
5
1
8
6
7
9
0
------解决方案--------------------join(),replce(),split()组合着用就可以了