View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Jun 28, 2002 12:50 am Post subject: Find EXACT Match In A List... |
|
|
Here's a search routine that finds all EXACT matches in a list.
The first routine matches only the word (case-sensitive), the
second matches the complete item (also case-sensitive).
__________________________________________________________________________________________________________________________
Code: |
LIST CREATE, 1
LIST LOADTEXT, 1,
"abc_duck_xyz
"abc_frog_xyz
"abc_turtle_xyz
"turtle
"abc_goose_xyz
"abc_Duck_xyz
"abc_Frog_xyz
"Turtle
"abc_Turtle_xyz
"abc_Goose_xyz
"abc_egg_xyz
rem -- Capital "T" is only difference between line 3 and line 7 --
%%word = "Turtle"
rem -- Word only match --
%x = 0
REPEAT
if @greater(@pos(%%word, @item(1, %x)), 0)
%p = @pos(%%word, @item(1, %x))
%s = @substr(@item(1, %x), %p, @sum(@pred(%p), @len(%%word)))
if @equal(%s, %%word, EXACT)
INFO %%word found in item %x@tab()
end
end
%x = @succ(%x)
UNTIL @equal(%x, @count(1))
rem -- Complete item match --
%x = 0
REPEAT
if @equal(%%word, @item(1, %x), EXACT)
INFO %%word matches complete item "("item %x")"@tab()
end
%x = @succ(%x)
UNTIL @equal(%x, @count(1))
|
EDIT1 - Optimized code some, changed to find all instances
(not just the first one), and added second routine to check
complete item match. Thanks to Dread for his input.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Last edited by Mac on Fri Jun 28, 2002 7:06 pm; edited 1 time in total |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Fri Jun 28, 2002 8:14 am Post subject: |
|
|
Immaculate as always, Mac!
Another possibility:
Code: |
LIST CREATE, 1
LIST LOADTEXT, 1,
"abc_duck_xyz
"abc_frog_xyz
"abc_turtle_xyz
"abc_goose_xyz
"abc_Duck_xyz
"abc_Frog_xyz
"turtle
"abc_Turtle_xyz
"abc_Goose_xyz
"abc_egg_xyz
"Turtle
"goose
%%word = "Turtle"
if @match(1,%%word)
REPEAT
%%found = @next(1)
if @equal(%%found,%%word,EXACT)
info Total match for '%%word' found at line @index(1)
end
UNTIL @not(@match(1,%%word))
end
|
This one returns only items that match the query 100%, i.e. case-sensitive and the search string
must equal the entire item (not only a part string).
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Jun 28, 2002 11:05 am Post subject: |
|
|
Hiya Dread,
Unfortunately, your example doesn't work on my system...
I've had problems with @next() for years though, sometimes
it works, sometimes it doesn't. I finally quit using it completely
(it's flaky in both VDS2 and VDS3). Also, @match() doesn't
always work well in a loop, although it works fine on a single
pass.
Here's how I'd do a search if the complete item must match:
Code: |
%x = 0
REPEAT
if @equal(%%word, @item(1, %x), EXACT)
INFO %%word matches complete item "("item %x")"@tab()
end
%x = @succ(%x)
UNTIL @equal(%x, @count(1))
|
BTW, I added this routine to my original post, and also
modified the first routine to find all instances of a search.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Sat Jun 29, 2002 2:31 am Post subject: |
|
|
Very odd. The find Complete Item Match does not work for me. But,
it should. I'll look into it a little more later, I'm just about ready
to lay my head on my kkkkkkeyyyyyybboaaaardddddddd (oops)
and fall asleep... _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|