Newbie3
Jan Schenkel
janschenkel at yahoo.com
Mon Dec 8 10:11:37 EST 2008
--- dunbarx <dunbarx at aol.com> wrote:
> Feels like old times. When I get to newbie4000 I can
> start helping out around here.
>
> So, fullFind...
>
> What I like about this gadget is its ability to
> return ALL matched instances by line, item or
> character. It returns chunk-based information about
> the location(s) of a string within a container. Even
> HC's old "search" XFCN from the power tools stack
> could do that.
>
> I wrote a few workarounds using the lineOffset
> function. They all do the job just fine in their own
> way, and I can implement one of them as a function
> and keep it in a library (a stack in use?). I am
> sure the other offSet functions will come in handy.
> I see there is already a native substitute
> for "fullReplace". Well and good.
>
> But I can write a substitute for fullFind in
> hypertalk, too. The lineOffset function only returns
> the first instance, so additional processing is
> required to get all of them. 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.
>
> Jacqueline, I finally got the "filter" command to
> work, but this simply extracts data; I lose the
> chunk positional information present in the original
> text. How would one use it to emulate fullFind?
>
> Grudgingly learning to like Revolution. (Sob) My
> belligerent stance derives only from loyalty.
>
> Oh yes, thanks to anyone who takes the trouble...
>
> Craig Newman
>
Hi Craig,
Here's a quick attempt:
##
function MyFindLines theTextToFind, theVariable
local theLines, theLineNumber
put 0 into theLineNumber
repeat for each line theLine in theVariable
add 1 to theLineNumber
if theLine contains theTextToFind then
put theLineNumber & comma after theLines
end if
end repeat
delete char -1 of theLines -- remove trailing comma
return theLines
end MyFindLines
##
The 'repeat for each' style of loop is extremely fast
- much faster than the old 'repeat with i = 1 to the
number of lines in theVariable' style.
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>
=====
"As we grow older, we grow both wiser and more foolish at the same time." (La Rochefoucauld)
More information about the use-livecode
mailing list