Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: Kai Edwards <email@hidden>
- Date: Tue, 05 Nov 2002 08:00:40 +0000
on Mon, 4 Nov 2002 14:44:17 -0500, Paul Skinner <email@hidden> wrote:
>
Bonus points for actually testing code Kai. I should know better than
>
to throw something up on the list before running it through the grinder.
>
>
As to your points; they're all good ones. Excepting [4]. Mea culpa on
>
all the others.
>
As for [4]...
>
> [4] BTW, while we're doing some trimming, you might want to try running your
>
> own initial suggestion (Tue, 29 Oct 2002 00:28:59 -0500) _without_ the three
>
> lines involving text item delimiters. (You may find they're not entirely
>
> essential to the operations involved there.) ;-)
>
>
No they're not essential, but I don't consider a script to be polite
>
if it doesn't store the TIDs and reset them at the end. I didn't
>
support this idea of resetting the TIDs for a long time, later I cursed
>
myself for being stupid and hardheaded. I now store and restore like I
>
should. If you don't it WILL bite you.
I don't think we differ on the issue of using TIDs, Paul. I agree that, if a
script uses TIDs, it should leave them as it finds them.
In my observation above, I was simply suggesting that your initial script
(Tue, 29 Oct 2002 00:28:59 -0500) stored, set and then restored the TIDs,
but didn't actually _use_ them.
To clarify what I mean, here's your original code (unchanged - except for
the removal of comments and TID lines):
-------------------------------
set potentialName to [NO BREAK]
"this/might not.be a legal:name, then again, it could be."
set legalName to {}
set illegalCharacters to {".", ",", "/", ":"}
repeat with thisCharacter in the characters of potentialName
set thisCharacter to thisCharacter as text
if thisCharacter is not in illegalCharacters then
set the end of legalName to thisCharacter
end if
end repeat
if length of legalName is greater than 32 then
set legalName to items 1 thru 32 of legalName as text
else
set legalName to legalName as text
end if
return legalName
-------------------------------
The method checks each character of the name individually, lists the
characters that pass the comparison test, and finally coerces the list to a
string (truncating to 32 characters as necessary). Since it works quite
happily without setting any TIDs, there's no need (IMO) to store or restore
them. (It may not be as fast as using TIDs - but that's another issue.)
I hope that explains better the point I was trying to make.
Best wishes.
Kai
--
email@hidden
email@hidden
_______________________________________________
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.