Re: Why doesn't this cause an error?
Re: Why doesn't this cause an error?
- Subject: Re: Why doesn't this cause an error?
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 23 Sep 2002 18:06:32 -0700
On 9/23/02 5:33 PM, "Mr Tea" <email@hidden> wrote:
>
set theName to "01 Picture"
>
set startHere to ((offset of " " in theName) + 1)
>
set endHere to ((offset of "." in theName) - 1)
>
>
set theDisplayName to text startHere thru endHere of theName
>
>
--> "Picture"
>
>
I originally tested this with 'theName' set to "01 Picture.jpg", but wanted
>
to see what would happen if the script encountered a file without a name
>
extension. I expected an error, but got none. The same result occurs if any
>
glyph that is not in the original string is used in place of "."
>
>
So, when the offset of a character that is not in a string is asked for, the
>
result returned is zero (the insertion point before the first letter). Is
>
this the intended behaviour, or a bug? The way things are, it means that I
>
don't need fancy checking routines to see if file names have extensions, but
>
a dialog telling me that the script can't get the offset of "." would have
>
seemed more likely.
If there's no offset, the offset indeed is 0, so that's the result you get.
I'm not sure why you think that's worse than getting an error. You just have
to set up an 'if the result = 0 then' condition to deal with it.
Generally speaking, if you can find some other way of doing something other
than 'offset', do the other way.
--
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.