Ugh. Bogged down...
Brian Yennie
briany at qldlearning.com
Fri Jun 11 01:55:26 EDT 2004
> I was trying to understand what you're saying, below, about replacing
> the
> (cr & cr) with cr, and don't see where you're referring to this in the
> original suggestion I'm working with. It is likely I missed something
> (important).
In the original question, IIRC you wanted to strip extra returns and
leading spaces from lines of text, particularly HTML. The suggestion to
use:
replace (cr&cr) with cr in tData
Is basically saying "whenever you find two consecutive returns, replace
them with one". A few passes through and you should find that all of
the extra returns are gone.
So something like this might be worth a try:
## put the field data into a variable for fast access
put fld "Imported_Raw" into tData
## keep replacing double return until there are none left
repeat while (tData contains (cr&cr))
replace (cr&cr) with cr in tData
end repeat
## keep replacing leading spaces until there are none left
repeat while (tData contains (cr&space))
replace (cr&space) with cr in tData
end repeat
There are probably a lot of interesting ways to go about the task- you
could also use the replaceText() function with a regular expression to
fix the whole thing in one pass. But RegEx isn't always fun...
> It would be awesome to get times like 5 seconds, but I must admit that
> I'll
> be happy to just get it in the 'couple-of-minutes' range!
>
> One of the lines provided to me says:
>
> repeat for each line tLine in tData
>
> As I'm working with further 'massaging' of the grabbed text, I'm
> playing
> with some of this code and this one left me scratching my head (and
> there
> ain't a lot of hair up there!) -- what is the function of the
> (variable?)
> tLine in this text? I didn't see it previously declared in the script
> and
> wondered why this wouldn't simply be:
>
> repeat for each line in tData
>
> Instead. Again, I'm sure I missed something important, but I really AM
> paying attention.
Think of the above syntax as a replacement for the slower (but still
available) syntax:
repeat with i=1 to (number of lines in tData)
put line i of tData into tLine
...
end repeat
Instead of using a counter variable, and also gaining lots of speed,
you can just write:
repeat for each line tLine in tData
...
end repeat
The results will be exactly the same- except that the second will run
much faster and syntax-wise, serves as a sort of shorthand for the
former.
> I also wanted to comment that one of the reasons I decided to go with
> Revolution instead of any of the other suggestions is the tone and
> helpfulness of the members of this list. I'm glad to be a member of a
> list
> where everyone seems to want to share ideas, rather than berate the
> newbies
> or 'one-up' the others on the list. Hopefully the developers remember
> those
> who bought in at the ground floor when they're rich and famous... (For
> those of you who've been around the Mac arena since 1983 (yes, I said
> "3"),
> think HyperCard, and FirstClass, etc.)
Amen! I think you'll find there's a real mix here: quite a few old
Hypercard hats mixed in with a little of everything else. Personally, I
can only trace my Hypercard roots back to about 1992, but in my
defense, I was 3 years old for the majority of 1983...
- Brian
More information about the use-livecode
mailing list