• 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: creating your own commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating your own commands


  • Subject: Re: creating your own commands
  • From: Shane Stanley <email@hidden>
  • Date: Sat, 26 Dec 2015 23:16:45 +1100

I know you all had a quite few days, because my emails to the list started bouncing on Christmas Eve, leaving you in temporary bliss. Alas, all good things come to an end...

on substring preceeding aSubstring from aParentString

Let me play the annoying pedant here: rule number 1 of libraries with terminology is to check the spelling. Getting it wrong makes things a lot harder to remember.

on substring following aSubstring from aParentString
set theLength to aSubstring's length
set the sourceString to current application's NSString's stringWithString:aParentString
set the searchString to current application's NSString's stringWithString:aSubstring
set theRange to sourceString's rangeOfString:searchString
set theRest to sourceString's substringFromIndex:((theRange's location) + (theLength))

I know I've posted similar code here a while back, so this is me correcting me. AppleScript calculates the length of a string by counting the number of grapheme clusters, whereas Cocoa calculates the number of 16-bit unichars. That means in most written languages in use, they are the same -- but not always. A good example of where that fails is text containing emoticons. So for accuracy's sake, that would be better as:

on substring following aSubstring from aParentString
set the sourceString to current application's NSString's stringWithString:aParentString
set the searchString to current application's NSString's stringWithString:aSubstring
set theRange to sourceString's rangeOfString:searchString
set theRest to sourceString's substringFromIndex:((theRange's location) + (theRange's |length|))


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

  • Follow-Ups:
    • Re: creating your own commands
      • From: 2551 <email@hidden>
References: 
 >creating your own commands (From: 2551 <email@hidden>)
 >Re: creating your own commands (From: 2551 <email@hidden>)

  • Prev by Date: Re: creating your own commands
  • Next by Date: Re: creating your own commands
  • Previous by thread: Re: creating your own commands
  • Next by thread: Re: creating your own commands
  • Index(es):
    • Date
    • Thread