[Coco] INSTR question

Mathieu Bouchard matju at artengine.ca
Fri Feb 10 14:29:20 EST 2017


Nope, it's like that in probably every language that has such a search 
function : an empty string is found at EVERY position in the string, therefore 
the first match it finds is wherever the search begins. It's the normal way of 
doing it, because it logically fits the way N characters are searched in a 
string, for N=0, and the behaviour you wish would mean adding a special case for 
N=0 where programmers prefer to define functions so that they have the least 
possible number of cases.

(However, in other languages, 0 is the first position in the string, whereas "no 
match" is represented by another value (such as -1 or nil or error))


Le 2017-02-09 à 15:12:00, Allen Huffman a écrit :

> ...but I noticed today it finds the empty string: ""
>
> PRINT INSTR("ABCDE", "")
> 1
>
> That seems like a bug.
> A$=""
> PRINT INSTR("ABCD", A$)
> 1

  ______________________________________________________________________
| Mathieu BOUCHARD --- tél: 514.623.3801, 514.383.3801 --- Montréal, QC


More information about the Coco mailing list