nisus.com
https://www.nisus.com/forum/

displaying the number of found text
https://www.nisus.com/forum/viewtopic.php?f=17&t=3285
Page 1 of 1

Author:  js [ 2009-01-17 02:34:48 ]
Post subject:  displaying the number of found text

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?

Author:  martin [ 2009-01-19 14:57:42 ]
Post subject:  Re: displaying the number of found text

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.

Author:  js [ 2009-01-20 08:29:08 ]
Post subject:  Re: displaying the number of found text

Ever so happy to discover a little secret. If "f" changes we will change with it. Thanks for helping.

Author:  martin [ 2009-01-20 13:40:16 ]
Post subject:  Re: displaying the number of found text

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.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/