forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Find EXACT Match In A List...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Fri Jun 28, 2002 12:50 am    Post subject: Find EXACT Match In A List... Reply with quote

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
View user's profile Send private message Send e-mail
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Jun 28, 2002 8:14 am    Post subject: Reply with quote

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
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Fri Jun 28, 2002 11:05 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Sat Jun 29, 2002 2:31 am    Post subject: Reply with quote

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... Smile

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group