Dgameman1 Posted March 1, 2016 Share Posted March 1, 2016 (edited) Dim $OldFoundMatchesUsernames[1] = ["Empty"] Global $BlackList[3] = ["8809708", $Username, "thakhy"] While 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $FoundUsernames = StringRegExp($MatchesHTML, 'Picture of (.*?)"', 3) $FoundMatchesUsernames = _ArrayUnique($FoundUsernames) _ArrayDelete($FoundMatchesUsernames, 0) For $j = 0 To UBound($BlackList) - 1 For $i = UBound($FoundMatchesUsernames) - 1 To 1 Step -1 If String($BlackList[$j]) = String($FoundMatchesUsernames[$i]) Then _ArrayDelete($FoundMatchesUsernames, $i) ExitLoop ;only when sure each Element in $FoundMatchesUsernames is unique Else EndIf Next Next ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If Not $OldFoundMatchesUsernames[0] == "Empty" Then For $j = 0 To UBound($OldFoundMatchesUsernames) - 1 For $i = UBound($FoundMatchesUsernames) - 1 To 1 Step -1 If String($OldFoundMatchesUsernames[$j]) = String($FoundMatchesUsernames[$i]) Then _ArrayDelete($FoundMatchesUsernames, $i) ExitLoop ;only when sure each Element in $FoundMatchesUsernames is unique Else EndIf Next Next EndIf Dim $OldFoundMatchesUsernames = $FoundMatchesUsernames Wend So, the first Part of the code that is within the ;s works perfectly fine in removing the strings inside of BlackList from the array FoundMatchesUsernames. But for some reason, I'm not able to delete the strings in FoundMatchesUsernames that are found in OldFoundMatchesUsernames Edited March 1, 2016 by Dgameman1 Link to comment Share on other sites More sharing options...
AutoBert Posted March 1, 2016 Share Posted March 1, 2016 Maybe there are whitespaces in the arraystrings, you can use StringStripWS to strip them. Can you please post some demodata for $MatchesHTML or $FoundMatchesUsernames? Link to comment Share on other sites More sharing options...
EmilyLove Posted March 1, 2016 Share Posted March 1, 2016 (edited) Wouldn't it be easier and faster to lose the for next loop entirely and replace it with these 2 lines of code: _ArrayAdd($FoundMatchesUsernames,$OldFoundMatchesUsernames);combines the 2 arrays into 1. $FoundMatchesUsernames=_ArrayUnique($FoundMatchesUsernames);Uniques the array. Edited March 1, 2016 by BetaLeaf Dgameman1 1 Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2016 Share Posted March 1, 2016 (edited) Because of the operators precedence, this If Not $OldFoundMatchesUsernames[0] == "Empty" Then is evaluated like this If (Not $OldFoundMatchesUsernames[0]) == "Empty" Then so it should (probably...) be written like this If Not ($OldFoundMatchesUsernames[0] == "Empty") Then Edited March 1, 2016 by mikell Dgameman1 1 Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 1, 2016 Author Share Posted March 1, 2016 4 hours ago, mikell said: Because of the operators precedence, this If Not $OldFoundMatchesUsernames[0] == "Empty" Then is evaluated like this If (Not $OldFoundMatchesUsernames[0]) == "Empty" Then so it should (probably...) be written like this If Not ($OldFoundMatchesUsernames[0] == "Empty") Then I changed it and you're 100% correct. I feel like an idiot lol. So in some cases, $FoundMatchesUsernames is going to have the same stuff as $OldFoundMatchesUsernames the second time through. The only issue is that the first row is still there instead of it all being removed? Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2016 Share Posted March 1, 2016 For $i = UBound($FoundMatchesUsernames) - 1 To 0 Step -1 ;<< loop to 0 Dgameman1 1 Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 2, 2016 Author Share Posted March 2, 2016 4 hours ago, mikell said: For $i = UBound($FoundMatchesUsernames) - 1 To 0 Step -1 ;<< loop to 0 You're the best! And I'm assuming I should just go ahead and change it for both then. Thanks so much Link to comment Share on other sites More sharing options...
EmilyLove Posted March 2, 2016 Share Posted March 2, 2016 If you are working with large arrays, you may want to consider my solution for optimization purposes. Dgameman1 1 Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 2, 2016 Author Share Posted March 2, 2016 5 hours ago, BetaLeaf said: If you are working with large arrays, you may want to consider my solution for optimization purposes. You're 100% correct. Thanks EmilyLove 1 Link to comment Share on other sites More sharing options...
mikell Posted March 2, 2016 Share Posted March 2, 2016 (edited) 7 hours ago, BetaLeaf said: If you are working with large arrays, you may want to consider my solution for optimization purposes. The best optimization by far would be to use Scripting.Dictionary #include <Array.au3> local $BlackList = ["xxx", "yyy", "zzz"] local $OldFoundMatchesUsernames = ["aaa", "bbb", "ccc", "ddd"] local $FoundMatchesUsernames = ["yyy", "ggg", "aaa", "eee", "xxx", "ddd", "ccc", "zzz", "fff"] ; create dictionary Local $sdFoundMatchesUsernames = ObjCreate("Scripting.Dictionary") ; $sdFoundMatchesUsernames.CompareMode = 1 ; case insensitive (if needed) ; build the dictionary (removing duplicates) For $i In $FoundMatchesUsernames $sdFoundMatchesUsernames.Item($i) Next ; remove blacklisted For $i In $BlackList $sdFoundMatchesUsernames.Remove($i) Next ; add $OldFoundMatchesUsernames (this also removes duplicates) For $i In $OldFoundMatchesUsernames $sdFoundMatchesUsernames.Item($i) Next ; get new $FoundMatchesUsernames array $FoundMatchesUsernames = $sdFoundMatchesUsernames.Keys() _ArraySort($FoundMatchesUsernames) _ArrayDisplay($FoundMatchesUsernames, "$FoundMatchesUsernames") Edit Comments added Edited March 2, 2016 by mikell Dgameman1 and Xandy 2 Link to comment Share on other sites More sharing options...
Dgameman1 Posted March 3, 2016 Author Share Posted March 3, 2016 Damn @mikell I would've never thought about it like that. Good looking out EmilyLove 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now