OK. I got it down to 2 seconds from 20.
Here's how.
My text is return delimited on a per line basis.
I added a return to the start of text or line 1 would be skipped. Just have to remove that return after this operation.
It's the looping through all the lines that is so slow. Since the lines may begin with a space, then every line really may start with a return and possibly spaces. So if I do a find and replace with the string return & " " and replace that with just return, using the text item delimiters, I thought it would be faster. And it sure is.
-- the new elven magic set myCountAfter to 0 set myCountBefore to 1 repeat while myCountBefore ≠ myCountAfter set myCountBefore to length of myText log myCountBefore set myResult to SpecialFindAndReplace(myText, return & " ", return) set myText to item 2 of myResult set myCountAfter to item 1 of myResult end repeat
-- found this somewhere and have been using it: on SpecialFindAndReplace(TheString, tofind, toreplace) set ditd to text item delimiters set text item delimiters to tofind set textItems to text items of TheString set text item delimiters to toreplace if (class of TheString is string) then set res to textItems as string else -- if (class of TheString is Unicode text) then set res to textItems as Unicode text end if set text item delimiters to ditd -- log res return {length of res, res} end SpecialFindAndReplace
Thanks to everyone for their help today. Made my Monday.
Cheers, - Alex Zavatone
This email message and any attachments are for the sole use of the intended recipient(s) and may contain information that is proprietary to U.S. Foodservice, Inc and/or its subsidiaries or otherwise confidential or legally privileged. If you have received this message in error, please notify the sender by reply, and delete all copies of this message and any attachments. If you are the intended recipient you may use the information contained in this message and any files attached to this message only as authorized by U.S. Foodservice. Files attached to this message may only be transmitted using secure systems and appropriate means of encryption, and must be secured using the same level password and security protection with which the file was provided to you. Any unauthorized use, dissemination or disclosure of this message or it's attachments is strictly prohibited.
|