Re: Trim?
Re: Trim?
- Subject: Re: Trim?
- From: Nigel Garvey <email@hidden>
- Date: Sun, 4 Aug 2002 11:42:34 +0100
Paul Skinner wrote on Sat, 3 Aug 2002 18:53:58 -0400:
>
NG's requires 14 iterations while mine takes 6. Over a larger text or
>
text with greater numbers of spaces it becomes very significant. It
>
requires contiguous white space of 160 characters before more than 21
>
iterations are required by my version.
>
>
I realize now that the version below is more efficient requiring only 15
>
loops to handle the 160 character run text...
>
>
set inputText to " email@hidden 'This is a > string?' "
>
cleanSpaces(inputText)
>
-->"email@hidden 'This is a > string?'"
>
>
on cleanSpaces(inputText)
>
set tag to "o#?"--opt shift k
>
set inputText to tag & inputText & tag
>
repeat while inputText contains " "
>
repeat with thesedelimiters in {{space & 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
>
>
This version will clean up space runs in the text of this entire posting
>
in 6 loops vs 433 for Nigel's.
How about this version of yours?
set inputText to " email@hidden 'This is a > string?' "
cleanSpaces(inputText)
-->"email@hidden 'This is a > string?'"
on cleanSpaces(inputText)
set space2 to space & space
set inputText to space & inputText & space
repeat while inputText contains space2
set AppleScript's text item delimiters to space2
set tempS to text items of inputText
set AppleScript's text item delimiters to space
set inputText to tempS as text
end repeat
set AppleScript's text item delimiters to ""
return text 2 thru -2 of inputText
end cleanSpaces
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.