Re: can I do this better?
Re: can I do this better?
- Subject: Re: can I do this better?
- From: Steven Angier <email@hidden>
- Date: Thu, 13 Jun 2002 09:10:57 +1000
On 13/6/02 3:47 AM, "garrett" <email@hidden> wrote:
>
on trimText(search_Text)
>
>
--if the seacrh-Direction is 1 then we search forward, examining the
>
first character of the text
>
--for any character in the Var removeChars (in our case returns or
>
spaces)
>
--if the Seacrh-Direction is -1 then we search backward form the last
>
character
>
>
repeat with i in searchDirection --first search forward then backward
>
>
set search_Text_Character to character i of search_Text --the
>
character to examine
>
>
repeat until removeChars does not contain search_Text_Character
>
if i = -1 then
>
set search_Text to characters 1 through ((length of
>
search_Text) - 1) of search_Text as string
>
else
>
set search_Text to characters 2 through ((length of
>
search_Text) - 1) of search_Text as string
>
end if
>
>
--since the Search Text has been trimmed we set the search
>
character the NEW last or first character
>
set search_Text_Character to character i of search_Text
>
end repeat
>
return search_Text
>
end repeat
>
>
end trimText
Good. A few things you could optimise:
* use "text n thru m" instead of "character n thru m"; it is faster
* rather than create a new string every time you find a white-space char;
just track the index of the offending characters and build a new string
once, at the end
* your function should remove other white space characters as well:
space, tab, return, lf, crlf
Steven Angier
Macscript.com
_______________________________________________
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.