Re: Wierd error
Re: Wierd error
- Subject: Re: Wierd error
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 23 Sep 2003 08:05:15 -0700
On 9/23/03 5:23 AM, "Paul Skinner" <email@hidden> wrote:
>
on trim(inputtext)
>
set valids to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a",
>
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
>
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C",
>
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
>
"R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
>
repeat with i from 1 to the length of characters of inputtext
>
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 the length of characters of inputtext
>
if character (-j) of inputtext is in valids then
>
set endValid to j
>
exit repeat
>
end if
>
end repeat
>
set trimedText to text startValid thru (-endValid) of inputtext
>
end trim
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
--
Paul Berkowitz
_______________________________________________
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.