Page 1 of 1 1
Topic Options
#203845 - 2011-11-25 09:32 PM Instr() - Odd behavior
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
I'm not sure this is a bug, but it seems strange to me that instr is returning 1 when the second parameter is empty. For example

 Code:
? instr("Apple,Banana,Grape","")


I tried this code with 4.53, 4.61, and 4.62 and they all did it.

Is this by design?


Top
#203847 - 2011-11-25 10:18 PM Re: Instr() - Odd behavior [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
took it little further.
 Code:
dim $s
instr("abc",$s) ?
$s=""
instr("abc",$s) ?


but thinking it logically, instr() forces the empty variable into string type, with translates to "". so it acutllay is logical on that part.

but I am not sure it should return 1, is it by design or not. cause that is not what the left most character is. one can easily think up loads of issues with that.
_________________________
!

download KiXnet

Top
#203851 - 2011-11-25 10:41 PM Re: Instr() - Odd behavior [Re: Lonkero]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Okay... well I'm going to move this to Beta then. Seems odd to me too.
Top
#205581 - 2012-08-26 01:55 PM Re: Instr() - Odd behavior [Re: Allen]
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Odd, indeed. In particular the fact that this issue has been around for so long.

I've changed InStr in 4.63 to return 0 (instead of 1) if an empty search string is specified.

Thanks for the report!

Ruud

Top
#207996 - 2013-11-04 04:35 PM Re: Instr() - Odd behavior [Re: Ruud van Velsen]
Bxn Offline
Getting the hang of it

Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
Hi guys !
Back after a (too) long job change, may I recall the somehow long discussions I initiated about this very subject in.. uhhh... 2002 : http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=80883 ?
Ruud, you explained at that time, that compatibility constraints (or consistency) with other languages prevented any change around null string eventually invoked in Instr() function !
I'm really glad for sure, it finally lead to this change :-)
Keep on the good job you do for so many years, best regards
___
BxN

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 509 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.053 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.