• 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: counting the records in a tab-delimited text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: counting the records in a tab-delimited text file


  • Subject: Re: counting the records in a tab-delimited text file
  • From: Kai Edwards <email@hidden>
  • Date: Sat, 22 Dec 2001 15:19:33 +0100

> Subject: Re: counting the records in a tab-delimited text file
> From: Bill White <email@hidden>
> To: Robert Castles <email@hidden>, =AppleScript
> Mailing List <email@hidden>
>
>> Can anyone give me a simple way of counting the number of records
>> (return-delimited records) in a tab-delimited text file? I know I can go
>> through and read each character, counting each return, but that seems like a
>> really inefficient way of getting the count. Thanks in advance,
>>
> Try using text item delimiters:
>
> set theFile to read file "Hard drive:Desktop folder:Text file" -- change to
> suit
>
> set oldDelims to AppleScript's text item delimiters
> set AppleScript's text item delimiters to return
>
> set recordCount to (count (text items of theFile)) - 1
>
> set AppleScript's text item delimiters to oldDelims
>
> return recordCount

Recently, in response to another question, I suggested a similar approach
(using text item delimiters). However, Michelle Steiner then offered a much
more direct solution using 'count paragraphs' - which could simplify the
script to something like this:

set theFile to read file "Hard drive:Desktop folder:Text file" -- change to
suit
set recordCount to (count paragraphs of theFile) - 1

--

**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************


  • Prev by Date: Re: Who uses AppleScript
  • Next by Date: MS Excel help !!!
  • Previous by thread: Re: counting the records in a tab-delimited text file
  • Next by thread: Re: Doing a boolean on a list [Correction]
  • Index(es):
    • Date
    • Thread