Re: Simple delete
Re: Simple delete
- Subject: Re: Simple delete
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 09 Mar 2004 11:26:14 -0800
On 3/9/04 10:32 AM, "Robert Poland" <email@hidden> wrote:
>
>
This simple delete appears not so simple. What am I missing?
>
>
tell application "Tex-Edit Plus"
>
set x to "09-Mar-04"
>
if item 1 of x = "0" then
>
delete item 1 of x
>
end if
>
end tell
>
x --> "9-Mar-04"
Strings are immutable - you can't replace "items" (characters), 'delete'
them, or add to them in place, as you can with lists, records and dates.
However, you can set a variable, including the same variable to a new string
which does any of those things with respect to the original string. You're
only playing with AppleScript variables and strings above, so it's the same
thing inside or outside a Tex-Edit tell block:
set x to "09-Mar-04"
if item 1 of x = "0" then
set x to text 2 thru -1 of x
end if
x --> "9-Mar-04"
You'd need to put a condition in there not to error if the string is nothing
but the character "0" - there's no text 2. I leave that to you.
BTW, you could also use
if x starts with "0" then
which might be quicker if you had immensely long strings and were doing this
in a repeat loop, 'item' or 'character' of a string forces AppleScript to
first make a list of every character. I don't suppose it really makes the
slightest bit of difference except in really exceptional circumstances,
however - you'd never notice the speed difference.
--
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.