Skip to main content
hamdifem
Inspiring
September 7, 2015
Answered

parent story numbering

  • September 7, 2015
  • 1 reply
  • 501 views

I am working on a test book

We are making arrangements in the answer key

Dropping a few questions, or changing location

before: 1-C 2-E 4-5-C 6-B 7-C 8-C 9-B 10-C

after:    1-C 2-E 3-4-C 5-B 6-C 7-B 8-C 9-C

I need it again later numbering

how a code can be written

var no = 1;

app.findGrepPreferences = app.changeGrepPreferences = null;      

var xx = app.findGrepPreferences.findWhat = "(\\d+)(\\-)(\\u)";

for(var i=0;i<xx.lenght;i++){

app.changeGrepPreferences.changeTo = i + "$2$3";

app.selection[0].parentStory.changeGrep(); 

}

app.findGrepPreferences = app.changeGrepPreferences = null;

This topic has been closed for replies.
Correct answer Peter Kahrel

Not sure what you mean by all this. Does your new code work? And what does 'sno' stand for?

To substract 1 from all numbers preceding capitals you can use this:

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = '\\d[-\\d]+\\u';

found = app.selection[0].findGrep();

for (i = found.length-1; i >= 0; i--) {

  found.contents = found.contents.replace (/(\d+)/, function() {return Number(arguments[1])-1;});

}

Peter

1 reply

Peter Kahrel
Community Expert
Community Expert
September 7, 2015

Any particular reason why the first two (1-C and 2-E) aren't changed?

hamdifem
hamdifemAuthor
Inspiring
September 7, 2015

all changed

before : 1-C 2-E 4-A 5-C 6-B 7-C 8-C 9-B 10-C

run script finaly

9-C 9-E 9-A 9-C 9-B 9-C 9-C 9-B 9-C


but I write new code and try


var sno = 0;

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "(\\d+)(\\-)";

var founds = app.selection[0].parentStory.findGrep();

for(k = 0; k < founds.length; ++k) {

    founds.contents = (++sno) + "-";

}

app.findGrepPreferences = app.changeGrepPreferences = null;

finaly: 1-C 2-E 3-A 4-C 5-B 6-C 7-C 8-B 9-C

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
September 7, 2015

Not sure what you mean by all this. Does your new code work? And what does 'sno' stand for?

To substract 1 from all numbers preceding capitals you can use this:

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = '\\d[-\\d]+\\u';

found = app.selection[0].findGrep();

for (i = found.length-1; i >= 0; i--) {

  found.contents = found.contents.replace (/(\d+)/, function() {return Number(arguments[1])-1;});

}

Peter