Replace characters with line number

Replace characters with line number

1
NewbieNewbie
1

    Oct 25, 2013#1

    Find - ABC
    Replace ABC & Line Number
    How can I do this?

    6,687587
    Grand MasterGrand Master
    6,687587

      Oct 26, 2013#2

      With just a replace, no chance.

      You need a macro or a script for this task. Here is a script solution.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Define environment for this script.
         UltraEdit.insertMode();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      
         // Define the parameters for the find.
         UltraEdit.ueReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=false;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
         {
            UltraEdit.activeDocument.findReplace.searchInColumn=false;
         }
      
         // Find case-sensitive all occurrences of "ABC" and replace
         // them by "ABC" + current line number.
         UltraEdit.activeDocument.top(); 
         while (UltraEdit.activeDocument.findReplace.find("ABC"))
         {
            var sLineNum = UltraEdit.activeDocument.currentLineNum.toString(10);
            UltraEdit.activeDocument.write("ABC"+sLineNum);
         }
         UltraEdit.activeDocument.top(); 
      }
      Best regards from an UC/UE/UES for Windows user from Austria