Re: Wierd error
Re: Wierd error
- Subject: Re: Wierd error
- From: Nigel Garvey <email@hidden>
- Date: Wed, 24 Sep 2003 02:50:17 +0100
Paul Berkowitz wrote on Tue, 23 Sep 2003 08:05:15 -0700:
>
You like typing quote marks? This will run much faster, since searching text
>
("is in") is much, much faster than searching lists:
>
>
my trim(" *%*&*!@#$^ |BLOW, JOE|* ^&*))&%^^%$ ")
>
--> BLOW, JOE
>
>
on trim(inputtext)
>
set valids to
>
"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
repeat with i from 1 to (count inputtext) -- count is faster too, and no
>
list
>
if character i of inputtext is in valids then
>
set startValid to i
>
exit repeat
>
end if
>
end repeat
>
repeat with j from 1 to (count inputtext)
>
if character (-j) of inputtext is in valids then
>
set endValid to j
>
exit repeat
>
end if
>
end repeat
>
set trimmedText to text startValid thru (-endValid) of inputtext
>
end trim
And don't forget 'considering case', arranging the most likely characters
towards the beginning of the 'valids' string, and only counting
'inputtext' once. As a safety feature, the whole process could go in a
'try' block with the first repeat going up to (count inputtext) + 1. If i
gets that far, it means there are no valid characters in inputtext and
the attempt to test beyond the end of the string will cause an error.
'trimmedText' can then be set to "" in the 'on error' block.
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.