Page 1 of 1
gettig all existing results from matchtext
Posted: Tue Aug 13, 2013 7:11 am
by infantilo
Hi,
how do i get all the existing results using matchtext, not only the first one?
text to search within
Code: Select all
matchtext(texttosearchwithin, "test", listofresults)
thanks for advice
Re: gettig all existing results from matchtext
Posted: Tue Aug 13, 2013 8:26 am
by Simon
Hi infantilo,
I wouldn't have used matchText for this.
Do you have to?
Simon
Re: gettig all existing results from matchtext
Posted: Wed Aug 21, 2013 3:53 pm
by MaxV
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.
Re: gettig all existing results from matchtext
Posted: Wed Aug 21, 2013 5:35 pm
by jacque
I'd use the "filter" command instead.
Re: gettig all existing results from matchtext
Posted: Wed Aug 21, 2013 8:39 pm
by dunbarx
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
Re: gettig all existing results from matchtext
Posted: Thu Aug 22, 2013 6:36 pm
by jacque
"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.