Re: Removing characters from a string
Re: Removing characters from a string
- Subject: Re: Removing characters from a string
- From: "Daniel A. Shockley" <email@hidden>
- Date: Tue, 5 Nov 2002 16:11:59 -0500
John Delacour wrote:
> If I write a handler called simpleReplace that takes three
parameters: source text, what-to-find, and what-to-replace-with,
that handler darn well better put back the text item delimiters to
what they were, not what the default is. Does the name
"simpleReplace" imply to anyone reasonable that "Oh, I'm going to
change the TIDs, too - good luck, sucker!"
Handlers are a special case where you obviously need to exit with the
same tids as were in operation when you called the handler.
Ah, well then, it sounds as if I don't disagree with you as strongly
as I thought. If you were talking about a short script, with all the
code in one block, then setting the TIDs to {""} when done is fine.
Of course, you'd want to be sure the code would never be copied and
pasted into a larger block of code, where it could cause problems.
I almost always save and restore the TIDs anyway, since what I've
done once may be useful again in the future.
The fastest way I've found to save and restore TIDs is the following:
set {oldTids, AppleScript's text item delimiters} to ,
{AppleScript's text item delimiters, {"<MY_NEW_DELIM>"} }
-- do stuff with MY_NEW_DELIM
set AppleScript's text item delimiters to oldTids
This doesn't take much time beyond changing them to something new,
and then changing them back to {""}, uses the same number of lines of
code, and has the added benefit of making the code block reusable. It
also makes me worry a lot less. :-)
On a related note, I've found that it is a good idea to restore TIDs
in an error-trapping block, as well. Many is the time I've been
working with TIDs, had an error, modified the code, ran it again, and
was surprised to get crazy results. Problem was the error happened
after I'd changed the TIDs, and before I'd restored them. Ouch!
--
----
Daniel A. Shockley
email@hidden
email@hidden
http://www.danshockley.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.