Insert sequential Line Numbers

Help with writing and running scripts

Insert sequential Line Numbers

Postby rwblinn » Sun Aug 07, 2011 2:12 am

Search for a script to insert sequential line numbers at the beginning of each line starting with 1. Line numbers to be followed by a dot, then space and content.
Example:
FROM
Line 1
Line 2
Line 3

TO
1. Line 1
2. Line 2
3. Line 3

Thank You,
Robert
rwblinn
Newbie
 
Posts: 2
Joined: Sun Aug 07, 2011 2:08 am

Re: Insert sequential Line Numbers

Postby Mofi » Sun Aug 07, 2011 4:00 am

I would do that simply with

  • Column - Column Mode to turn column editing mode on,
  • Column - Insert/Fill Columns to insert ". ",
  • Column - Insert Number to insert the numbers,
  • Column - Column Mode to turn column editing mode off
  • and perhaps additionally a simple tagged regular expression to move the spaces right the inserted numbers to left.
Those commands can be either executed on entire file or just some lines selected in column mode.

But you want a script, so here is a script executing the commands as listed above:

Code: Select all
if (UltraEdit.document.length > 0)
{
   UltraEdit.insertMode();
   UltraEdit.activeDocument.top();

   UltraEdit.columnModeOn();
   UltraEdit.activeDocument.columnInsert(". ");
   UltraEdit.activeDocument.columnInsertNum(1,1,false,false);
   UltraEdit.columnModeOff();

   // Move the inserted spaces right the inserted numbers to left.
   UltraEdit.ueReOn();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=false;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=true;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   UltraEdit.activeDocument.findReplace.replace("%^([0-9]+^)^( +^)","^2^1");
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Insert sequential Line Numbers

Postby rwblinn » Mon Aug 08, 2011 9:44 am

This is the script I have been loking for.
Appreciate your help,
Robert
rwblinn
Newbie
 
Posts: 2
Joined: Sun Aug 07, 2011 2:08 am


Return to Scripts

cron