looping over lines in the selection

looping over lines in the selection

8
NewbieNewbie
8

    May 19, 2008#1

    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

    21
    Basic UserBasic User
    21

      May 20, 2008#2

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

      Code: Select all

      UltraEdit.insertMode();
      UltraEdit.hexOff;
      UltraEdit.ueReOn();
      if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
      else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.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);
      }
      

      6,682583
      Grand MasterGrand Master
      6,682583

        May 20, 2008#3

        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.
        Best regards from an UC/UE/UES for Windows user from Austria

        8
        NewbieNewbie
        8

          May 20, 2008#4

          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.