Re: Count word's occurences
Re: Count word's occurences
- Subject: Re: Count word's occurences
- From: Shane Stanley <email@hidden>
- Date: Mon, 08 Sep 2014 19:36:35 +1000
On 8 Sep 2014, at 5:53 pm, Guido Tangorra <email@hidden> wrote:
This is working fine, but I'm wondering if there's a better or a more efficient way to do the same. Maybe with grep or ASObjC Runner or with a built-in command in TextWrangler.
It's pretty easy to do with an ASObjC-based library in Mavericks or later -- there's a class just for the job:
use framework "Foundation"
on indexList:theList set theCountedSet to current application's NSCountedSet's alloc()'s initWithArray:theList set theEnumerator to theCountedSet's objectEnumerator() set newList to {} repeat set anObject to theEnumerator's nextObject() if anObject is missing value then exit repeat set theCount to theCountedSet's countForObject:anObject set end of newList to {anObject as text, theCount} end repeat return newList end indexList: -- 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