Jump to content

[solved] copy file if found in array


Tosyk
 Share

Recommended Posts

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 ;)

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...