a little help with "find" script

dunbarx at aol.com dunbarx at aol.com
Fri Mar 9 16:47:03 EST 2012


I wrote this in HC about 1990, ported over to LC. It predated the godLike Rinaldi. Completely straightforward:



function revFullFind tText,tFind,exactly --RETURNS LINE NUMBER & "," & WORD NUMBER
   put 0 into counter
   switch exactly
      case "true"
      case empty
         repeat for each line tline in tText
            add 1 to counter
            if tFind = tline then
               put counter & return after tResult
            end if
         end repeat
         break
      case "false"
         repeat for each line tline in tText
            add 1 to counter
            if tFind is in tline then
               repeat with y = 1 to the number of words in tLine
                  if word y of tLine = tFind then put y & "," after temp
               end repeat
               delete last char of temp
               put counter & "," & temp & return after tResult
               put "" into temp
            end if
         end repeat
         break
   end switch
   return tResult
end revFullFind


tText is your field text, tFind is, well, you know, and "exactly" should be "false" in your case. And yes, you need to run this for each field in each card, but that should only add about six more lines to your handler.


Craig Newman







-----Original Message-----
From: Timothy Miller <gandalf at doctorTimothyMiller.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Fri, Mar 9, 2012 3:32 pm
Subject: a little help with "find" script


Oops. Forgot how to do this. Knew it once. I don't write scripts every day. Not 
even every month.

Please remind me how to write a script that finds and records every instance of 
a string in field "foo" I know how to write repeat loops, but can't remember how 
to keep finding and then exit when the last instance is found.

It would be helpful to add a user entry to the dictionary about this. If I can 
do it correctly and coherently, I'll add one myself.

Many cards in this stack contain field "foo" Field foo may contain none, one or 
many instances of the string I will be looking for.

I will  not necessarily be on card one when I start searching and the cursor may 
or may not be inserted in field foo. Not all cards contain field foo

Let's put all the foundchunks into tVar. I can take it from there.

After "char x to y of field z" I need to add the id of the card where the 
foundchunk was found. It would be convenient to know the id rather than the 
number of field z.

I can't remember if some function similar to the foundchunk includes the card ID 
of the foundchunk, or if I have to script it. The long foundchunk? Probly not...

I don't need a correct working script, just a few hints.

Your little hints save me hours of dictionary-studying and trial and error 
scripting. I really appreciate them.

Tim



_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list