Re: Trim?
Re: Trim?
- Subject: Re: Trim?
- From: Nigel Garvey <email@hidden>
- Date: Sun, 4 Aug 2002 00:32:52 +0100
Paul Skinner wrote on Sat, 3 Aug 2002 12:09:57 -0400:
>
On Saturday, August 3, 2002, at 09:24 AM, Nigel Garvey wrote:
[text and script snipped]
>
You could skip some of the looping.
>
>
set inputText to " email@hidden 'This is a > string?' "
>
cleanSpaces(inputText)
>
-->"email@hidden 'This is a > string?'"
>
>
on cleanSpaces(inputText)
>
set tag to "o#?"
>
set inputText to tag & inputText & tag
>
repeat while inputText contains " "
>
repeat with thesedelimiters in {{space, tag}, {tag & tag, tag}, {tag,
>
space}}
>
set AppleScript's text item delimiters to item 1 of thesedelimiters
>
set tempS to text items of inputText
>
set AppleScript's text item delimiters to item 2 of thesedelimiters
>
set inputText to tempS as text
>
end repeat
>
end repeat
>
set AppleScript's text item delimiters to ""
>
return (characters 2 thru -2 of inputText) as text
>
end cleanSpaces
That looks like a contradiction at first, with your nested loops. :-) But
I see what you mean. My script loops once through all the text items;
yours loops a few times through just six delimiters. Mine generates less
waste stringage and listage and is in fact two-and-a-half to
four-and-a-half times as fast as yours with that particular input text
(depending on the system I use to test it). However, as the input texts
grow longer (ie. there are more spaces), yours rapidly catches up and
soon becomes the faster of the two. Pretty neat. :-)
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.