mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2004
Posts: 291
W
Fjord artisan
OP Offline
Fjord artisan
W
Joined: Jun 2004
Posts: 291
what i am doing is using a whle loop to search for the
text.
so if i typed !find bla bla bla
it would look through the file for those words.
it works well for searching 1 word
like but if the search string is like:
!find this is an example
it will look for the exact sentance

whereas i want it so
it will search each separate word
so
example:
!find this is an example

it will find reaults like
this_is_an_example_
or in a different order
this example an is
and i am using the script like

alias !find {
var %i = 1,%t = $calc($lines(test.txt) + 1)
while (%i < %t) {
if (text string here isin $read(test.txt, %i)) {
echo -a Found: $read(test.txt, %i)
inc %i
}
}
}


any ideas thanks smile

Joined: Mar 2003
Posts: 1,271
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,271
Try something along the following line:

Code:
[color:green]; little tokenizing to avoid gettok crap[/color]
var %x = $2-
var %y = 1
tokenize 32 %x
:check
[color:green]; search the textfile for $1[/color]
if ($read(filename,w,$+(*,$1,*)),%y) {
  [color:green]; if a line is found, check for the other tokens[/color]
  var %x = $read(filename,$readn)
  if ($2 isin %x) &amp;&amp; ($3 isin %x) &amp;&amp; ($4 isin %x) msg $nick found on line $readn : $read(filename,$readn)
}
else {
  inc %y
  goto check
}


DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
Bear in mind you can use $read with a wildmatch to search for a string on any line at any position in a file, e.g. $read(file,w,*string*) returns (with evaluation) the first line matching *string*. In your case, if you want to find lines to match all words in a query in any order, /filter with an alias would be suitable:

; Usage: /findtext file query
; Example: /findtext file.txt word1 word2 word3

findtext {
set -u %tmp.query
filter -fk $1 findtext2 $+(*,$2,*)
unset %tmp.query
}

findtext2 {
var %line = $1-,%i = 1
tokenize 32 %tmp.query
while (%i <= $0) {
if ($($ $+ %i,2) !isin %line) return
inc %i
}
echo Found: %line
}

So it filters all lines containing the first word to the alias, then loops through the query to check if all words in the query exist in the line.

Edit: Sorry, I keep interrupting you today it seems LoB, spent a while typing/testing.

Last edited by Sigh; 30/09/04 06:08 AM.
Joined: Jun 2004
Posts: 291
W
Fjord artisan
OP Offline
Fjord artisan
W
Joined: Jun 2004
Posts: 291
cool thanks for the replys

got it working

thanks
smile

just wondering though

is there any way to do this:
(bla isin blai) || (bli isin blai) {
instead of using || all the time
is it possible to do it a quiker way

like
(bla,bli isin bla) {

or something simalar to make it smaller

thanks smile

Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
You can use the following alias which loops until the last parameter checking if each substring exists in the string:

; $isin(string,N,substring1,substring2,...)
; Returns the Nth substring, if N = 0 it returns the number of matches

alias isin {
var %i = 3,%n = 0,%x
while (* iswm $($ $+ %i,2)) {
%x = $v2
if (%x isin $1) {
inc %n
if (%n = $2) return %x
}
inc %i
}
return $iif(!$2,%n)
}

To apply it to your purpose, checking if (substring isin $1-) || (substring2 isin $1-) you can now just use if ($isin($1-,0,substring,substring2))

Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
is there any way to do this:
(bla isin blai) || (bli isin blai) {
instead of using || all the time
is it possible to
Code:
  var %GoodToks bla,bli
  if ($istok(%GoodToks, $1, 44)) { return $true }
  return $false


NaquadaBomb
www.mirc-dll.com

Link Copied to Clipboard