Re: creating your own commands
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|))
|
_______________________________________________
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