Re: Found count of on text item
Re: Found count of on text item
- Subject: Re: Found count of on text item
- From: Matthew Broms <email@hidden>
- Date: Wed, 10 Oct 2001 12:23:20 -0400
This worked fantastically Marc. My processing time went from just under 5
minutes to 15 seconds, literally. It's so simple I hate I forgot about the
power of the delimiter. Thanks for reminding me.
Matt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
From: "Marc K. Myers" <email@hidden>
>
Organization: [very little]
>
Reply-To: email@hidden
>
Date: Thu, 04 Oct 2001 17:17:13 -0400
>
To: email@hidden
>
Subject: Re: Found count of on text item
>
>
> Date: Thu, 04 Oct 2001 16:04:10 -0400
>
> Subject: Found count of on text item
>
> From: Matthew Broms <email@hidden>
>
> To: Applescript Users <email@hidden>
>
>
>
> Is there a fast way to return the number of occurrences of a particular
>
> string in a large text document. For example, in a 1mb text document, how
>
> many times does "abc123" occur? I'm just looking for the found count.
>
>
This is the best approach I know of:
>
>
set srchStrng to text returned of [optn-L]
>
(display dialog "Enter the text to search for:" default answer "")
>
set theFile to (choose file with prompt "Pick the file to search:" [optn-L]
>
of type {"TEXT"})
>
set fileID to (open for access theFile)
>
set theText to read fileID
>
set {od, AppleScript's text item delimiters} to [optn-L]
>
{AppleScript's text item delimiters, srchStrng}
>
set theText to text items of theText
>
set AppleScript's text item delimiters to od
>
display dialog ("The string occurs " & ((count theText) - 1) as text) &
>
[optn-L]
>
" times in the file"
>
>
NB: "[optn-L]" stands in for the AppleScript continuation character
>
>
Marc K. Myers <email@hidden>
>
http://AppleScriptsToGo.com
>
4020 W.220th St.
>
Fairview Park, OH 44126
>
(440) 331-1074
>
>
[10/4/01 5:16:22 PM]
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users