Re: Missing value
Re: Missing value
- Subject: Re: Missing value
- From: Jon Pugh <email@hidden>
- Date: Sun, 28 Aug 2011 13:29:34 -0700
On Aug 28, 2011, at 1:10 PM, Ron Hunsinger wrote: On Aug 28, 2011, at 12:10 PM, Christopher Stone wrote: if appName ends with ".app" then set shortAppName to text 1 thru ((offset of ".app" in appName) - 1) of appName
This use of offset is not robust. What if appName is "Nifty.appliance.app"? If you know the extension (because you hard-coded it) you know its length and can hard-code that too.
if appName ends with ".app" then set shortAppName to text 1 thru -5 of appName
If you can't hardcode the length, either because you didn't hard-code the extension or you want to minimize your use of magic constants:
if appName ends with anExtension then set shortAppName to text 1 thru (-1 - length of anExtension) of appName
This is the kind of thing where my SmartString class shines:
tell SmartString setString(appName) set shortAppName to beforeString(".app") end SmartString if shortAppName = "" then set shortAppName to appName -- no .app extension
For example...
Jon
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden