将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

相关内容

  • 没有找到相关文章

最新更新