首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > vbScript >

ASP数组中去掉重复的,写入一个新的数组中解决思路

2012-02-20 
ASP数组中去掉重复的,写入一个新的数组中有一个数据里面的很多重复的数据,现要去掉重复的,写入一个新的数

ASP数组中去掉重复的,写入一个新的数组中
有一个数据里面的很多重复的数据,现要去掉重复的,写入一个新的数组 ,怎么写?
如:aa = Array("11","22","33","11","112233","33","22","44","44","11","ff","22","22","去")

[解决办法]

VBScript code
<%aa = Array("11","22","33","11","112233","33","22","44","44","11","ff","22","22","去")Set dic = CreateObject("Scripting.Dictionary")For i=0 To UBound(aa)    If Not dic.Exists("_" & aa(i)) Then        dic.Add "_" & aa(i), aa(i)    End IfNextbb = dic.Items()Set dic = NothingResponse.Write Join(bb,",")%>
[解决办法]
VBScript code
aa = Array("11","22","33","11","112233","33","22","44","44","11","ff","22","22","È¥")k = -1For i = 0 To UBound(aa)    b = True    For j = 0 To k        If aa(i) = r(j) Then            b = False            Exit For        End If    Next    If b Then        k = k + 1        ReDim Preserve r(k)        r(k) = aa(i)    End IfNexts = Join(r, ",")
[解决办法]
VBScript code
aa = Array("11","22","33","11","112233","33","22","44","44","11","ff","22","22","去")a = "," & Join(aa,",") & ","For i = 0 To UBound(aa)    b = "," & aa(i) & ","    b2 = ",XXXX" & aa(i) & "XXXX,"    a = Replace(a, b, b2 ,1,1)    a = Replace(a, b, ",")    a = Replace(a, b2, b)Next Response.Write  Mid(a,2,Len(a)-2)
[解决办法]
LS思路不错,不过太不通用,对于XXXXYYXXXX之类的会无视。
VBScript code
On Error Resume Nextaa = Array("11","22","33","11","112233","33","22","44","44","11","ff","22","22","去")Set oRecordSet = CreateObject("Adodb.RecordSet")    With oRecordSet        For Each item In aa            .Fields.Append item,200,32        Next    End With            For Each item In oRecordSet.Fields        WScript.Echo item.Name    Next    Set oRecordSet = Nothing 

热点排行