• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why doesn't this cause an error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Why doesn't this cause an error?
      • From: Mr Tea <email@hidden>
References: 
 >Why doesn't this cause an error? (From: Mr Tea <email@hidden>)

  • Prev by Date: Extra data in resource or attached file?
  • Next by Date: Strange QP
  • Previous by thread: Why doesn't this cause an error?
  • Next by thread: Re: Why doesn't this cause an error?
  • Index(es):
    • Date
    • Thread