All the discussion on seeding _INSTRREV got me thinking about how I'd actually like a seed function to work in INSTR(), and it isn't as is. Let's say you're searching for commas in a comma delimited string like: ",1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ," Now let's say I want everything from after the 4th comma. Well with INSTR() as is, I have to count up to where in the string that occurs, which is at position 13. So we have rec$ = mid$(s$, instr(13, s$, ",") + 1, 1), which returns "4"
OK, wouldn't it be easier to have a method to just ask for the seed to be set to the 4th search position? In other words: rec$ = mid$(s$, instr(4, s$, ",") + 1, 1)
So the function would have to process the sub-string from the sting the number of times requested. This is something we generally have to code ourselves, but I could easily see the function doing it. It's just parsing, after all...
s$ = ",1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,"
PRINT "QB64 INSTR(): "; rec$;
" using 13-characters in as the seed: At position";
INSTR(13, s$
, "") + 1 recx$
= MID$(s$
, instrx&
(4, s$
, ",") + 1, 1)PRINT "INSTR Function: "; recx$;
" using 4(th) occurrence as the seed. At position"; instrx&
(4, s$
, ",") + 1
Now that code won't stand, as considerations would have to be given for how it should act when a search term is not found, when a search term is present, but the seed is larger than the string, etc. Codeguy probably would have a faster method, anyway. So I didn't want to do a lot of extra work on this now, but I did want to use some simple code just to demonstrate the topic of discussion.
BTW - I'm not requesting INSTR() be changed. It needs to stay as is, to be QB compatible, of course. I just wanted to throw this idea out for discussion. I mean maybe I'm missing something else the seed, as it functions in INSTR() now, is needed for?
Pete