Tosyk Posted December 6, 2020 Author Share Posted December 6, 2020 @water thank you very much! Link to comment Share on other sites More sharing options...
Skysnake Posted December 6, 2020 Share Posted December 6, 2020 @Tosyk did you see this? https://www.autoitscript.com/wiki/Arrays#Comparing_Arrays Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Nine Posted December 6, 2020 Share Posted December 6, 2020 Wiki is a tad misleading in its explanation about comparing arrays as a whole. Lets take a different example : Local $Array1[3] = [1, 2, 3] Local $Array2[3] = [1, 2, 4] If $Array1 == $Array2 Then ConsoleWrite("1.) is found equals" & @CRLF) ; as Wiki is showing in its example If $Array1 = $Array2 Then ConsoleWrite("2.) is NOT found equals" & @CRLF) ; not mentionned in Wiki example Wiki says : Quote I have the impression that such comparisons compare the memory address of the arrays instead of the array elements values. Maybe when using =, it is comparing memory address. But definitely not when using == as help file clearly states : Quote Tests if two strings are equal. Case-sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case-sensitive. So based on this definition, when using ==, it is like making this comparaison : If String($Array1) = String($Array2) Then ConsoleWrite("1.) is found equals" & @CRLF) No offense Wiki “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted December 6, 2020 Share Posted December 6, 2020 7 hours ago, Nine said: Maybe when using = Then again, maybe not: Local $Array1[3] = [1, 2, 3] If $Array1 = $Array1 Then ConsoleWrite("You will NEVER see this print") 7 hours ago, Nine said: But definitely not when using == Agree, definitely not: If $AnyArray == $AnyOtherArray Then ConsoleWrite("You will ALWAYS see this print") Of course: If _ArrayToString($AnyArray) == _ArrayToString($AnyOtherArray) Then ConsoleWrite("You MIGHT see this print") If _ArrayToString($AnyArray) = _ArrayToString($AnyOtherArray) Then ConsoleWrite("If you saw ^THAT^ you'll defintely see this, and maybe even if you didnt't") Summary: If you need the result of an array comparison to always be False, use = If you need the result of an array comparison to always be True, use == If you need the result of an array comparison to be True when all elements are equal and False if any are not, compare the elements, perhaps by using _ArrayToString. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Skysnake Posted December 10, 2020 Share Posted December 10, 2020 @Nine I do not know who wrote the Wiki entry, but if you point me to the offending bits, and supply better text, I will update it. Skysnake Why is the snake in the sky? 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