Modify

Opened 15 years ago

Closed 15 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 Changed 15 years ago by jchd

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 Changed 15 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

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.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Gary.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.