• 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: Found count of on text item
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Found count of on text item


  • Subject: Re: Found count of on text item
  • From: "Marc K. Myers" <email@hidden>
  • Date: Thu, 04 Oct 2001 17:17:13 -0400
  • Organization: [very little]

> 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]


  • Follow-Ups:
    • Re: Found count of on text item
      • From: Matthew Broms <email@hidden>
  • Prev by Date: Re:Quark 5
  • Next by Date: Re: Alternatives to Scriptable Text Editor
  • Previous by thread: Found count of on text item
  • Next by thread: Re: Found count of on text item
  • Index(es):
    • Date
    • Thread