- A command to check if every item in two arrays are equal - that both arrays are exactly the same.
From the docs:
From what it sounds like, using an object in an if statement only checks to see if both values refer to the same object. An array checking command would be nice.When an object reference is compared with some other value using one of = == != <>, they are considered equal only if both values are references to the same object.
Objects are always considered true when a boolean value is required, such as in if obj, !obj or obj ? x : y.
An object's address can be retrieved using the &address-of operator. This uniquely identifies the object from the point of its creation to the moment its last reference is released.
Of course, a solution can be made with AutoHotkey:But an AHK solution would be faster and easier.Code: Select all
SameArray(array1, array2) { Loop, % (%array1%.MaxIndex() > %array2%.MaxIndex) ? %array1%.MaxIndex() : %array2%.MaxIndex() { if(%array1%[A_Index] != %array2%[A_Index]) return 0 } return 1 }
- A command to check if any item in the array contains a string. I did not find anything in the docs that could have been this.
AHK solution:Code: Select all
ArrayContains(array, searchfor) { Loop, % %array%.MaxIndex() { if(%array%[A_Index] = searchfor) { return 1 break } } return 0 }
- Lastly a command to search and remove a string from and array.
I could not get a function to return the array with the removed item, so it just returns the position of the item.Code: Select all
ArrayRemove(ByRef array, searchfor) { index = 0 Loop, % %array%.MaxIndex() { if(%array%[A_Index] = searchfor) { return A_Index } } return 0 }
More Simple Array Commands
- dangerdogL2121
- Posts: 173
- Joined: 01 Oct 2013, 23:11
More Simple Array Commands
Simple arrays are already very nice to have, but it seems like there could be a few more commands. By simple arrays I mean "real" arrays and not dynamic variables.
- dangerdogL2121
- Posts: 173
- Joined: 01 Oct 2013, 23:11
Re: More Simple Array Commands
Oh, I see tidbit already posted about arrays.
Who is online
Users browsing this forum: No registered users and 4 guests