Reverse search and case-insernsitive search routines - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: Reverse search and case-insernsitive search routines (/showthread.php?tid=2571) |
Reverse search and case-insernsitive search routines - TDarcos - 04-04-2024 i had a need of a routine to do the opposite of INSTR( in which I wanted to find the last appearance of a search field in the target string. So I wrote the following functions:
I'm not sure how useful this would be, but I suspect someone is going to need one of these at some point. The functions include a program that runs a set of tests to confirm they work. RE: Reverse search and case-insernsitive search routines - SMcNeill - 04-04-2024 https://qb64phoenix.com/qb64wiki/index.php/INSTRREV RE: Reverse search and case-insernsitive search routines - Pete - 04-04-2024 Glad to see I'm not the only one who is Wikilliterate around here. Anyway, kudos for writing your own version. I dd the same several years back, before _INSTRREV came along. It's a big help for word wrap in WP apps. I had a bit of a go-around with Fell when _INSTRREV first came out, regarding the seed parameter. _INSTRREV keeps the same forward seed counting as INSTR. There are reasons for that, which slip my mind at the moment, but I do recall I made an easy workaround, so it could seed backwards. Compare these two... Code: (Select All)
Pete RE: Reverse search and case-insernsitive search routines - SMcNeill - 04-04-2024 @Pete The reason is for easy splitting of the string. a$ = "C:\My Dir\My File.txt" Now, get the last slash in that string, to break it down to path + file: path$ = LEFT$(a$, _INSTRREV(a$, "\")) file$ = MID$(a$, _INSTRREV(a$, "\") + 1) RE: Reverse search and case-insernsitive search routines - Pete - 04-04-2024 But your example is SEEDLESS. Great if you're growing grapes, but let's not wine about it... Code: (Select All)
So a couple of chop methods, but my initial contention was when we count in reverse, we should seed in reverse. I let that go, because there is at least a since of continuity that even though the searching part of the string has been reversed, the seeding order, from beginning to end, remains constant. Pete RE: Reverse search and case-insernsitive search routines - PhilOfPerth - 04-04-2024 (04-04-2024, 12:38 AM)SMcNeill Wrote: https://qb64phoenix.com/qb64wiki/index.php/INSTRREV Hadn't noticed this one! Could be quite useful for some of my little progs. RE: Reverse search and case-insernsitive search routines - eoredson - 04-15-2024 Here are some custom Instr functions. The first as a string comparison, the second a filename comparison. The string one allows * and ? where the second one has *, ?, ^ comparison. Erik. |