therms Posted May 11, 2008 Share Posted May 11, 2008 Given arrays 1 and 2, does anyone have any suggestions on how to create array 3 which contains everything from array 1 except that which is in array 2?Example array 1a b c d e f gExample array 2d e bExample array 3a b c f g Link to comment Share on other sites More sharing options...
monoceres Posted May 11, 2008 Share Posted May 11, 2008 Loops and arrays goes hand in hand #include <array.au3> Dim $a1[5]=[1,4,7,10,23] Dim $a2[2]=[4,10] Dim $a3[1] For $i=0 To UBound($a1)-1 For $j=0 To Ubound($a2)-1 If $a1[$i]=$a2[$j] Then ContinueLoop 2 Next _ArrayAdd($a3,$a1[$i]) Next _ArrayDelete($a3,0) _ArrayDisplay($a3) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
monoceres Posted May 11, 2008 Share Posted May 11, 2008 Here's the same thing without Array.au3 (I'm currently trying to avoid it in my scripts since it's horrible slow): Dim $string Dim $a1[5]=[1,4,7,10,23] Dim $a2[2]=[4,10] Dim $a3[1] For $i=0 To UBound($a1)-1 For $j=0 To Ubound($a2)-1 If $a1[$i]=$a2[$j] Then ContinueLoop 2 Next ReDim $a3[UBound($a3)+1] $a3[UBound($a3)-1]=$a1[$i] Next For $h=1 To UBound($a3)-1 $string&=$h&": "&$a3[$h]&@CRLF Next MsgBox(0,"Array Display",$string) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
weaponx Posted May 11, 2008 Share Posted May 11, 2008 Looks familiar:http://www.autoitscript.com/forum/index.ph...p;hl=arraymerge Link to comment Share on other sites More sharing options...
monoceres Posted May 11, 2008 Share Posted May 11, 2008 Looks familiar:http://www.autoitscript.com/forum/index.ph...p;hl=arraymerge how do you mean? Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
therms Posted May 12, 2008 Author Share Posted May 12, 2008 Thank you very much guys. For some reason my brain just wasn't working this afternoon. Now let me ask if I'm approaching my task in the best way possible. Array1 is actually a list of all files in a directory. Array2 is a subset of Array1. I want to delete all files except for those in Array2. My first thought was to create a third array as described above and then delete those files. Thoughts? Link to comment Share on other sites More sharing options...
monoceres Posted May 12, 2008 Share Posted May 12, 2008 I say it's okay, especially since the code I posted basically is just two loops so it should run pretty fast Broken link? PM me and I'll send you the file! 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