Repeat speed and stripping chars

Ivers, Doug E Doug_Ivers at lord.com
Wed Jan 9 08:41:01 EST 2002


> >2.
> >Seems that the word parser is little more than an item 
> parser with the
> >itemDelimiter set to " ", except for the stupid behavior 
> with quotes.  I
> >would like a true word parser.  Or a parser for which we can specify
> >multiple delimiters.  Like a java token function.  What is 
> the best/fastest
> >way to parse words even in the presence of quotes and punctuation?
> 
> There are several ways. The brute force method shouldn't be 
> dismissed -- try a repeat for each char C in myString and see 
> if it meets your needs. Note that the repeat form is critical 
> for performance. If you repeat with i = 1 to whatever, that 
> will start fast and slow down quickly as the string grows. 
> Repeat for each starts faster and stays fast no matter the 
> size of the string.
>

Thanks, Geoff!  The speed of "repeat for each char..." is a valuable
revelation for me!  With this new understanding, what would be the most
efficient code for a
"stripChars(theText,theChars)" function?  Normally, I would say "repeat with
i = number of chars of theText down to 1" so that I can delete chars with
out messing up the indexing.  Is there a similar way to reverse the "repeat
for each..."?  If not, should I pull out the chars I want and assemble a new
return string?

-- D





More information about the use-livecode mailing list