Text manipulation
Posted: 2011-09-01 01:08:40
I’m translating a book, and my (human) editor wants to have the page numbers of the original in the translated document. The page numbers are in the form “[123]” (left square bracket, 1–3 numerals, right square bracket) in a separate paragraph.
Currently, a Quickeys macro applies a paragraph style, types the brackets, and puts the cursor inside. It occurred to me that the functionality of this macro could be extended, not so much for convenience as a fun way to learn Nisus’ macro language.
What I want the macro to accomplish is to search backwards in the document to the previous page number, select the number part, increment this with +1, go back to the end, and paste the next page number complete with square brackets and paragraph style.
By scrupulous perusal of the Nisus macro reference, I found out how to find the previous page number (was I proud!).
finds backwards and selects strings like
[1]
[34]
[219]
Now I’m stuck on the hard part: how to manipulate the result. I must confess that I’m slightly dizzied by what seems to be a myriad of options in the macro reference. There must be a way to
1) select the numerical part of the found string (or to strip the brackets),
2) increment the resulting value with +1
I would appreciate any pointers in the right direction. The rest of the macro I believe I can figure out on my own.
Currently, a Quickeys macro applies a paragraph style, types the brackets, and puts the cursor inside. It occurred to me that the functionality of this macro could be extended, not so much for convenience as a fun way to learn Nisus’ macro language.
What I want the macro to accomplish is to search backwards in the document to the previous page number, select the number part, increment this with +1, go back to the end, and paste the next page number complete with square brackets and paragraph style.
By scrupulous perusal of the Nisus macro reference, I found out how to find the previous page number (was I proud!).
Code: Select all
Find '\[[0-9]+\]', 'Emr'
[1]
[34]
[219]
Now I’m stuck on the hard part: how to manipulate the result. I must confess that I’m slightly dizzied by what seems to be a myriad of options in the macro reference. There must be a way to
1) select the numerical part of the found string (or to strip the brackets),
2) increment the resulting value with +1
I would appreciate any pointers in the right direction. The rest of the macro I believe I can figure out on my own.