I was wondering how to compare 2 lists, via string or array, and acquire the values that did not compare.
I'm thinking of something similar to the PHP function array_diff()
.
Is it possible with classic ASP?
You could use 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.