Need some help I don't quite get all this dot stuff

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Need some help I don't quite get all this dot stuff

Post by loulesko » 2010-07-18 00:53:41

I'm trying to extract the chapter number from the text "Chapter 3" which is a previous find from the cursor position. I'm trying to use the following

$sels = $doc.text.find '(?<=Chapter )[[:digit:]](?=\\n)', 'Er-Wr', '-am'

How do I get the number three from $sels it just gives me ranges. I'm not quite hip to this type of coding any help and education appreciated.

thanks
Lou

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Need some help I don't quite get all this dot stuff

Post by Kino » 2010-07-18 01:44:57

loulesko wrote:I'm trying to extract the chapter number from the text "Chapter 3" which is a previous find from the cursor position. I'm trying to use the following

$sels = $doc.text.find '(?<=Chapter )[[:digit:]](?=\\n)', 'Er-Wr', '-am'

How do I get the number three from $sels it just gives me ranges.
You can get the number by $n = $sels.subtext or $n = $sels.substring but find command does not know where the cursor is positioned and, with r option, always searches from the end of the document. Try the following instead:

Code: Select all

Find '(?<=Chapter )[[:digit:]]+(?=\n)', 'Er-W', '-am'
$n = Read Selection
Prompt $n
And if you want to verify if the number has been found successfully . . .

Code: Select all

$i = Find '(?<=Chapter )[[:digit:]]+(?=\n)', 'Er-W', '-am'
if $i
	$n = Read Selection
	Prompt $n
else
	Prompt 'Chapter number not found'
end
• I added + (one or more times) after [[:digit:]] because your document may have more than nine chapters.
• You don’t need putting two \ before n although Macroize does.

User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Need some help I don't quite get all this dot stuff

Post by loulesko » 2010-07-19 17:20:35

Kino,

Amazing. Thank you again for all your help.

best
Lou

Post Reply