EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     duplicate lines macro
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
user
Posted on: 9/23/2011 1:31 pm
Home away from home
Joined: 9/29/2006
From:
Posts: 212
duplicate lines macro
hello

this macro deletes duplicate lines:

// Create an array  a = new Array();    // Fill the array a with all lines (with returns) in the document.  document.selection.StartOfDocument();  for( ; ; ){      y = document.selection.GetActivePointY( eePosLogical );      document.selection.SelectLine();      sLine = document.selection.Text;      if( sLine == "" ) {   // Reached the end of document, escape from the loop          break;      }      a.push( sLine );      document.selection.Collapse();      if( document.selection.GetActivePointY( eePosLogical ) == y ) {          // Reached the end of document (the last line without return), escape from the loop          break;      }  }    // Delete duplicate elements.  for( i = 0; i < a.length; i++ ){      sLine = a[i];      for( j = i + 1; j < a.length; j++ ){          if( sLine == a[j] ){              a.splice( j, 1 );              j--;          }      }  }    // Replace the entire document with new elements  document.selection.SelectAll();  document.selection.Text = a.join( "" );


does it leave the first/upper instance of the duplicate lines? or the last?

thanks!
Flat Previous Topic | Next Topic


Subject Poster Date
 » duplicate lines macro user 9/23/2011 1:31 pm

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文