Reply to topic  [ 4 posts ] 
displaying the number of found text 
Author Message

Joined: 2007-04-12 14:59:36
Posts: 229
Can the number of found text be caught in a macro? F.e. if yoy are only interested in how many times a selected textstring appears in the document, how would a macro look like that display number of found text, not leaving the actual caret postion?


2009-01-17 02:34:48
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
That is something you can do:
Code:
# save selection
$doc = Document.active
$selections = $doc.textSelections

# count found instances
$count = Find 'red', 'a'

# restore selection and prompt
$doc.setSelections($selections)
Prompt "Found $count instances."

I actually would have thought you could you use the "S" Find option, which means preserve the selection, but that only works for Replace commands. I'll have to file that as a bug. In the meantime, you could use the super secret "f" option, which would shorten the macro considerably:
Code:
$count = Find 'red', 'af'
Prompt "Found $count instances."

This would also run quicker, if efficiency is important. Unfortunately the "f" option may change its letter at some point.


2009-01-19 14:57:42
Profile WWW

Joined: 2007-04-12 14:59:36
Posts: 229
Ever so happy to discover a little secret. If "f" changes we will change with it. Thanks for helping.


2009-01-20 08:29:08
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Glad to help! The next update will have the "S" option fixed for Find commands, so you can simply use "S" instead of "f" and it will work as intended.


2009-01-20 13:40:16
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software