Filtering numbers

Help with writing and running scripts

Filtering numbers

Postby Gradius » Wed Jan 09, 2013 2:27 pm

Hi,

I need a simple script where it filter numbers.

Input (yes, there are tabs instead spaces):
Code: Select all
1   3   7   9   10   17   21   22   29   30   32   36   60   67   69   70   73   77   98   100
1   10   11   12   13   16   22   29   45   46   48   49   51   57   59   63   73   78   91   94

Output needs to be ('tabs' were converted into 'spaces' and 100 into 00):
Code: Select all
01 03 07 09 10 17 21 22 29 30 32 36 60 67 69 70 73 77 98 00
01 10 11 12 13 16 22 29 45 46 48 49 51 57 59 63 73 78 91 94

Numbers 1, 2, 3, 4, 5, 6, 7, 8 and 9, needs to becomes 01, 02, 03, 04, 05, 06, 07, 08 and 09 too.

Thank you!
Gradius
Newbie
 
Posts: 7
Joined: Thu Feb 02, 2012 5:52 pm

Re: Filtering numbers

Postby Mofi » Thu Jan 10, 2013 1:36 am

Good description of what should be done by the script and therefore easy to write the script.

Code: Select all
// Run this script only when at least 1 file is opened.
if (UltraEdit.document.length > 0)
{
   // Define environment for script.
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.ueReOn();

   // Set caret to top of file and remove spaces/tabs at end of all lines.
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.trimTrailingSpaces();

   // Define the parameters for the replaces.
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   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=true;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;

   // Replace all sequences of tabs/spaces by a single space.
   UltraEdit.activeDocument.findReplace.replace("[ ^t]+", " ");

   // Truncate numbers with more than 2 digits using a tagged regular expression.
   UltraEdit.activeDocument.findReplace.replace("[0-9]+^([0-9][0-9]^)", "^1");

   // Insert a leading zero on those numbers having only 1 digit.
   UltraEdit.activeDocument.findReplace.matchWord=true;
   UltraEdit.activeDocument.findReplace.replace("^([0-9]^)", "0^1");
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts