displaying the number of found text
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?
- martin
- Official Nisus Person
- Posts: 5227
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: displaying the number of found text
That is something you can do:
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:
This would also run quicker, if efficiency is important. Unfortunately the "f" option may change its letter at some point.
Code: Select all
# 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."
Code: Select all
$count = Find 'red', 'af'
Prompt "Found $count instances."
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.
- martin
- Official Nisus Person
- Posts: 5227
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
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.