簡體   English   中英

比較2個字符串或數組與輸出

[英]Compare 2 strings or arrays with output

我想知道如何通過字符串或數組比較2個列表,並獲取未比較的值。

我正在考慮類似於PHP函數array_diff()

經典ASP可以嗎?

您可以使用Scripting.Dictionary:

Public Function RemoveMatches(byVal arrRemove(), byVal arrMatches)
    Dim sdScriptingDictionary, Item, arrReturn

    Set sdScriptingDictionary = CreateObject("Scripting.Dictionary")
    sdScriptingDictionary.RemoveAll
    sdScriptingDictionary.CompareMode = BinaryCompare
    For Each itemRemove in arrRemove
        For Each itemMatches in arrMatches
            If itemMatches<>itemRemove Then
                'Response.Write "ADD:" & itemRemove & ":" & itemMatches & "<br />"
                If Not sdScriptingDictionary.Exists(itemRemove) Then sdScriptingDictionary.Add itemRemove, itemRemove
            Else
                'Response.Write "REMOVE:" & itemRemove & ":" & itemMatches & "<br />"
                If sdScriptingDictionary.Exists(itemRemove) Then sdScriptingDictionary.Remove(itemRemove)
                Exit For
            End If
        Next
    Next
    arrReturn = sdScriptingDictionary.keys

    'Clean Up
    Erase arrRemove
    Set arrRemove = Nothing

    Erase arrMatches
    Set arrMatches = Nothing

    sdScriptingDictionary.RemoveAll
    Set sdScriptingDictionary = Nothing

    RemoveMatches = arrReturn
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM