looping over lines in the selection

Help with writing and running scripts

looping over lines in the selection

Postby mrmtmo » Mon May 19, 2008 5:23 pm

Is there a way to loop over each line in the current selection?

e.g.

for each line in selection
// do something to this line if it matches criteria
end for

I see the selection property in the help but it is documented as read only.

-Michael
mrmtmo
Newbie
 
Posts: 8
Joined: Mon May 19, 2008 3:26 pm

Re: looping over lines in the selection

Postby Jaretin » Tue May 20, 2008 2:25 am

Don't know what exactly you want.
May this will help you.

Code: Select all
UltraEdit.insertMode();
UltraEdit.hexOff;
UltraEdit.ueReOn();
UltraEdit.columnModeOff();
var CRLF = "\r\n"; /* LineFeed character */

var myLines = UltraEdit.activeDocument.selection;
lines = myLines.split( CRLF );
for ( i in lines ) {
//check any condition you want. here just true
   if ( true ) {
      lines[i] = "" + i + " " + lines[i];
   }
}
for ( i in lines ) {
   UltraEdit.activeDocument.write(lines[i]+CRLF);
}
User avatar
Jaretin
Basic User
Basic User
 
Posts: 19
Joined: Sun Mar 25, 2007 11:00 pm

Re: looping over lines in the selection

Postby Mofi » Tue May 20, 2008 3:24 am

And do you know that you can run a Replace All in the just selected area. With tagged regular expressions this method is normally the fastest and easiest method to reformat a selection.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: looping over lines in the selection

Postby mrmtmo » Tue May 20, 2008 9:15 am

Thanks for the responses! It gives me some avenues to test.

Basically, I just looking to write a script that will process a selection that contains lines of C++ declarations or definitions. One of the characters I need to manipulate is the semicolon at the end of a line. Replace All might compromise other semicolons (e.g. for loops) unless I use regular expressions... which I could do I suppose.
mrmtmo
Newbie
 
Posts: 8
Joined: Mon May 19, 2008 3:26 pm


Return to Scripts