6
NewbieNewbie
6

    Mar 02, 2012#16

    How can I replace:
    something1 x something2 something3
    something4 x something5 something6
    something7 x something8 something9

    with:
    something1 1100 something2 something3
    something4 1101 something5 something6
    something7 1102 something8 something9

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 02, 2012#17

      Why do you need a script for that task?

      For the text you posted there is no need to replace x by an incrementing number with a script. This can be done easily with column mode features.
      • Press Alt+C or click on Column - Column Mode to enable the column editing mode.
      • Select the column with x using mouse or arrow keys.
        Special hint: Holding left Alt key and selecting with mouse makes a column selection without explicitly enabling column editing mode.
      • Click on Column - Insert Number, enter in the dialog 1100 and click on button OK
      • Press again Alt+C or click again on Column - Column Mode to disable the column editing mode. This last step is only needed when step 1 was not omitted because of making the selection with mouse while holding Alt key.
      And that's it. There is no need for a script to insert an incrementing number within a column on all lines of a file or just some lines.

      However, if you need a simple script for this simple task, here it is.

      Code: Select all

      if (UltraEdit.document.length > 0) {
      
         // Ask user of script for simple string to find.
         var sFind = UltraEdit.getString("Enter string to replace:",1);
      
         if (sFind != "") {  // Continue only if a string was entered.
            // Define environment for script.
            UltraEdit.insertMode();
            if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
            else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
            UltraEdit.activeDocument.hexOff();
            UltraEdit.ueReOn();
      
            // Define the fixed replace parameters for the script.
            UltraEdit.activeDocument.findReplace.mode=0;
            UltraEdit.activeDocument.findReplace.matchCase=false;
            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;
            }
            UltraEdit.activeDocument.findReplace.preserveCase=false;
            UltraEdit.activeDocument.findReplace.replaceAll=false;
            UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
      
            // Ask the user for the starting value.
            var nNumber = UltraEdit.getValue("Enter starting number:",1);
      
            // The replace is done from current position in file to end of file.
            while (UltraEdit.activeDocument.findReplace.replace(sFind,nNumber.toString())) {
               nNumber++;
            }
         }
      }
      Please note that you can't define the replace parameters like Match Case, Match Whole Word Only, Regular Expressions, etc. during script execution with the script as is. You need to do it in the script file itself. Or you add lots of extra lines asking the user of the script for all replace options and set the replace parameters accordingly.

      6
      NewbieNewbie
      6

        Mar 02, 2012#18

        I've forgotten to mention that there is possibility to have some other lines between those ones that I've been stated.

        Like:
        something1 x something2 something3
        something4 something5 something6
        something7
        x something8 something9

        Thanks!

        Read more posts (-12 remaining)