Re: need something faster
Re: need something faster
- Subject: Re: need something faster
- From: "Nigel Garvey" <email@hidden>
- Date: Sun, 5 Jun 2005 00:06:30 +0100
Hudson Barton wrote on Sat, 4 Jun 2005 07:49:18 -0400:
>What the following handler does is clean up a text string that
>contains unwanted characters and formats the result with regular line
>endings. It is way too slow when processing a long string. Any
>suggestions?
on cleanup(dirtytext)
-- Append to a list, don't concatenate ever-longer strings.
script o
property cleantext : {}
end script
-- Make this OSAX call once only.
set lf to ASCII character 10
set r to 1
-- Use 'considering case' if you only want upper case or numbers.
considering case
repeat with i from 1 to (count dirtytext)
set c to character i of dirtytext
if (c is in "ABCDEF1234567890") then
set end of o's cleantext to c
if (r = 40) then
set end of o's cleantext to lf
set r to 1
else
set r to (r + 1)
end if
end if
end repeat
if (o's cleantext does not end with lf) then set end of o's
cleantext to lf
end considering
-- Convert the list to string.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set cleantext to o's cleantext as string
set AppleScript's text item delimiters to astid
return cleantext
end cleanup
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden