Newbie3

dunbarx at aol.com dunbarx at aol.com
Mon Dec 8 14:23:55 EST 2008


Thanks,

I can live with repeats if they are fast. These are. So be it.


-----Original Message-----
From: J. Landman Gay <jacque at hyperactivesw.com>
To: How to use Revolution <use-revolution at lists.runrev.com>
Sent: Mon, 8 Dec 2008 1:38 pm
Subject: Re: Newbie3


dunbarx wrote:?
?
> The?
> lineOffset function only returns the first instance, so additional?
> processing is required to get all of them.?
?
That's why the last parameter is important; it allows you to search for an offset starting at a particular location. If you omit the last parameter, the search always starts at 1.?
?
So this:?
?
? get lineoffset(var,"ab")?
?
will consistently return the first instance in the text variable. You need to set up a "skip" parameter:?
?
? put 0 into skip?
? repeat?
? put lineoffset("ab",var,skip) into tResult?
? if tResult = 0 then exit repeat?
? put tResult & comma after tList?
? add tResult to skip -- start next search at last found location?
? end repeat?
?
> So, wow me with Rev's?
> arsenal. How to do it without a repeat loop? Find all "ab" in:?
> > abc def abc?
> > I want "1,3" back at me, or somesuch.?
?
You need the repeat loop above, but it is extremely fast. You can process many thousands of lines in under a second, usually. The above gives you what you want, provided you are looking for the exact string match for "ab". You could also get chunk info instead:?
?
? put fld 1 into var?
? put 0 into skip?
? repeat?
? put lineoffset("ab",var,skip) into tLine?
? if tLine = 0 then exit repeat?
? add tLine to skip?
? get matchChunk(line skip of var,"(ab)",tMatchStart,tMatchEnd)?
? put tMatchStart && tMatchEnd & cr after tList?
? end repeat?
?
This gives the start and end position of the string you are searching for, within the line you are looking at. So if you get "1 3" in the match, then the chunk refered to would be "char 1 to 3 of line <skip> of fld 1".?
?
If you want a regex search instead of an exact match for "ab" then you'd ?set up a filter first and then run a variation of the above repeat on the results of your filtered text. Something like this:?
?
? put fld 1 into var?
? filter var with "a*b*"?
? repeat for each line tLine in var?
? get matchChunk(tLine,"(a?
? put tMatchStart && tMatchEnd & cr after tList?
? end repeat?
?
Or you could use matchtext instead to extract the exact text.?
?
-- Jacqueline Landman Gay | jacque at hyperactivesw.com?
HyperActive Software | http://www.hyperactivesw.com?
_______________________________________________?
use-revolution mailing list?
use-revolution at lists.runrev.com?
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:?
http://lists.runrev.com/mailman/listinfo/use-revolution?




More information about the use-livecode mailing list