Modify

Opened 17 years ago

Closed 17 years ago

#1142 closed Bug (No Bug)

_ArraySearch return 0 (number vs string)

Reported by: JKFN Owned by: Gary
Milestone: Component: Standard UDFs
Version: 3.3.1.1 Severity: None
Keywords: _ArraySearch Cc:

Description

#Include <Array.au3>
Dim $array[1]
$array[0]=0
$output=_ArraySearch($array,"string")

$output is not -1, but 0

Attachments (0)

Change History (2)

comment:1 by jchd, 17 years ago

I may be mis-interpreting something here but it is my understanding that:
[from Helpfile, Datatypes]

If a string is used as a number, an implicit call to Number() function is done.
So if it doesn't contain a valid number, it will be assumed to equal 0.
For example,

10 * "fgh" equals the number 0.

So I'm not completely surprised that the comparison made (0 = "string") is interpreted as (0 = Number("string")) which is (0 = 0) and thus succeeds at index 0 of the array given in exemple.

Disclaimer: of course it can be objected that comparing oranges with keyboards is by itself a bad idea. OTOH the variant nature merely invites such operations.

comment:2 by Valik, 17 years ago

Resolution: No Bug
Status: newclosed

The equality test is essentially:

0 = Number("string")

The statement Number("string") returns 0 which compares true against 0 which means the search was successful and the index was found.

This is not a bug.

Modify Ticket

Action
as closed The owner will remain Gary.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.