Count word's occurences
Count word's occurences
- Subject: Count word's occurences
- From: Guido Tangorra <email@hidden>
- Date: Mon, 08 Sep 2014 09:53:03 +0200
I'm generating a text document in TextWrangler, a sort of name list, dinamically with AS.
This could be an example of the file I'm generating:
-----------
apple
grape
banana
ananas
orange
apple
apple
orange
--------------
I need to print the occurrences of every word in this document too.
So I would something like:
-----------
apple 1
grape 1
banana 1
ananas 1
orange 1
apple 2
apple 3
orange 2
--------------
I'm using this handler:
#Word Counter
on findLr(the_string, charTF)
set AppleScript's text item delimiters to charTF --use of the searched string to separate bits
set the_list to text items of the_string --put those bits in a list
set charNbr to ((count of the_list) - 1) --count those bits, minus 1
set AppleScript's text item delimiters to ""
return charNbr
end findLr
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.
The file has thousands of lines and it's generated dynamically so the performances are critical.
_______________________________________________
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