• 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: Count of Tab characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Count of Tab characters


  • Subject: Re: Count of Tab characters
  • From: Allen Watson <email@hidden>
  • Date: Sat, 20 Jan 2001 17:35:10 -0800

On or near 1/19/2001 1:35 PM, Bill Planey at email@hidden
observed:

> (I am trying to do this in MS Word 98, for what that's worth)...
>
> I cannot figure out the correct syntax to count the number of
> tab characters in a document (or a line, or a paragraph). I have tried
> the following, usint a document which I know has a total of 5 tabs in it:
>
> set tabChar to ASCII number 9
> set TabCount to count of tabChar
> display dialog "There are " & TabCount & " tab characters in this
> document."
>
> but I get this message in the event log:
>
> tell application "Microsoft Word"
> ASCII number 9
> --> 57
> count 57
> --> Microsoft Word got an error: 57 doesn't understand the count
> message.
>

"count" gives the number of somethings in the object, usually characters or
items (in a list). It is a verb, not a property, so the correct syntax would
be "count tabchar" and not "count of tabchar" (the latter form is used for
things like "first word of document", or another example, "count words of
document"). However, you don't want to use "count" directly on tab
characters; you need something to locate them first, and then count the
pieces the tabs separate.

tell application "Microsoft Word"
set allText to text of document 1 -- The front document
end tell
set od to AppleScript's text item delimiters -- Save existing state
set AppleScript's text item delimiters to tab
set temp to text items of allText
set AppleScript's text item delimiters to od -- Restore
-- We now have a list of text items which were separated by tabs. The list
-- will contain one more item than there were tabs, so...
set tabCount to (count items of temp) - 1
display dialog "There are " & tabCount & " tabs in this document."
--
Peace be with you!
Allen <email@hidden> XNS Name: =Allen Watson
My web page: <http://home.earthlink.net/~allenwatson/>
Scripts for OE and Entourage: <http://homepage.mac.com/allenwatson/>


  • Follow-Ups:
    • Re: Count of Tab characters
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Deleting locked files
  • Next by Date: Re: file selection dialog
  • Previous by thread: Count of Tab characters
  • Next by thread: Re: Count of Tab characters
  • Index(es):
    • Date
    • Thread