简体   繁体   English

比较2个字符串或数组与输出

[英]Compare 2 strings or arrays with output

I was wondering how to compare 2 lists, via string or array, and acquire the values that did not compare. 我想知道如何通过字符串或数组比较2个列表,并获取未比较的值。

I'm thinking of something similar to the PHP function array_diff() . 我正在考虑类似于PHP函数array_diff()

Is it possible with classic ASP? 经典ASP可以吗?

You could use Scripting.Dictionary: 您可以使用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