Hi guys I like your attention about INSTR features so I have thought that it is better to begin another thread instead to occupy that of Terry about QB64sourcecode.com.
Here our wiki that shows us the peculiarities of INSTR
https://www.qb64.org/wiki/INSTRINSTR (startSearching%, InWhatStringtosearch$, WhatwesearchString$)
INSTR returns 0 if an empty baseString$ is passed, and returns 1 with an empty searchString$
the second affirmation is not 100% true as demonstrated by Bplus's code here
https://www.qb64.org/forum/index.php?topic=2487.msg117466#msg117466and also this affirmation is not true as demonstrated by the above linked code
The start% position had to be at least 1 or greater when used or there will be an Illegal function call error. In QB64, a start% value of 0 or negative is interpreted as 1 and doesn't generate an error.
INSTR returns 0 when it searches before the beginning position of the string in which it searches, and after the end of the string in which it researches
but following the thinking of Steve to explain better why the original autors of STRING have choosen to return 1 if you search a nullstring into the baseString$ (InWhatStringToSearch$)
a$ = ""
b$ = "abcd"
c$ = a$ + b$
but if we append as 6 & 7 lines
we realize that nullstring is something for INSTR and nothing for LEN and PRINT. Its dual aspect let me remeber the electron in atom and the principle of undetermination of Heisenberg
I stress here that I write to talk and not to want to change INSTR, it's a QBASIC statement that QB64 emulates very well.
here code to explore these features of INSTR, a good keyword with a little black side...
PRINT "Nullstring at the start position of a basestring " a$ = ""
b$ = "abcde"
c$ = a$ + a$ + a$ + b$
' it is added 3 times a nullstring at the beginning of the string c$
' now teorically c$ has gained 3 more characters (of nullstring)
' they are not visible on printing but they are here.
' so LEN of c$ now should report 8 and not 5 as at beginning
' moreover going from 1 to 8 I must always get the result >0
PRINT "a$ = "; a$;
"-";
"b$= "; b$;
" ";
"c$= "; c$
PRINT " Result position basestring searchstring"
I find the situation similar to the answer that you can give at this question "How many 0 are in the digit 1?"
if your approach is mathematical the question becomes "How many 0 are added to digit 1 to let 1 be itself?"
The answers -infinite , 0, + infinite of zero value are all correct because all these operations let 1 be itself
if you approach is rapresentational the question becomes "How many 0 can be written before and after 1 to let 1 be itself?"
The answers seem equal to the previuos question, In fact 1 = 01 = 001 = 0001 = 0001.0= 00001.0000 etc etc etc
Thanks to read and to talk