gettig all existing results from matchtext

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
infantilo
Posts: 12
Joined: Sat Aug 10, 2013 5:16 pm

gettig all existing results from matchtext

Post by infantilo » Tue Aug 13, 2013 7:11 am

Hi,
how do i get all the existing results using matchtext, not only the first one?

text to search within

Code: Select all

test
karl
neuer test
hugo
test

Code: Select all

matchtext(texttosearchwithin, "test", listofresults)
thanks for advice

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: gettig all existing results from matchtext

Post by Simon » Tue Aug 13, 2013 8:26 am

Hi infantilo,
I wouldn't have used matchText for this.
Do you have to?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: gettig all existing results from matchtext

Post by MaxV » Wed Aug 21, 2013 3:53 pm

Livecode Embed SQLite, do you like (or need) to use a database? See: http://livecode.wikia.com/wiki/SQLite

Or you can use find working with fields, or you can use offset working with variables, for example:

Code: Select all

put texttosearchwithin into temp
put 0 into counter
repeat while offset("test",temp) > 0
 add 1 to counter
 put offset("test",temp) into listofresults[counter]
 delete  chars 1 to n of temp
end repeat
This way listofresults is an array containing all "test" position found.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: gettig all existing results from matchtext

Post by jacque » Wed Aug 21, 2013 5:35 pm

I'd use the "filter" command instead.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: gettig all existing results from matchtext

Post by dunbarx » Wed Aug 21, 2013 8:39 pm

Lots of answers, but I do not know what you really want to do with that list. You say "get the existing results"...

Delete all lines that do not contain (or fully match) the text in question? (Jacque's take on it)

Use the "find" command to locate all instances? (MaxV's)

Locate the lines that equal (or contain) the text? A possible function, tText is your list, tFind is your text to find, "exactly" ("true" or "false") is to choose between lines that equal or merely contain tFind:

Code: Select all

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
Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: gettig all existing results from matchtext

Post by jacque » Thu Aug 22, 2013 6:36 pm

"Filter" does remove lines, that's true. If I don't want to destroy the original list, I just make a copy and filter that. It's quick and doesn't require a repeat loop. But Craig's right, it would be good to know what the final goal is. For example, using filter won't give you line numbers for the matching lines.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply