This script isn't working 100%. It should count numbers (01 to 00, as 00 is like 100, or 01 to 99, then 00) and should display the total of each number.
For example:
01 = 3000
02 = 2994
...
00 = 2999
But 50% of numbers are being skipped. It doesn't count them all.
Numbers are like 01 03 05 07 08 09 10 15 28 34 38 42 47 51 ... 99 00 (each line ends with an enter).
Real result (limited to 50 numbers, and should be 100):
For example:
01 = 3000
02 = 2994
...
00 = 2999
Code: Select all
if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.hexOff();
// Get current caret position in active file.
var nActLineNum = UltraEdit.activeDocument.currentLineNum;
var nActColNum = UltraEdit.activeDocument.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActColNum++;
// Select the entire file and load contents into a string variable.
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel()) { // Is the file not empty?
var sAllLines = UltraEdit.activeDocument.selection;
// Restore initial caret position.
UltraEdit.activeDocument.gotoLine(nActLineNum,nActColNum);
// Get first line from string variable.
var nFirstLineTerm = sAllLines.indexOf("\r\n");
if (nFirstLineTerm > 0) // Has the file at least 1 line termination
{ // and the first line is not empty line?
var sFirstLine = sAllLines.substring(0,nFirstLineTerm);
// Replace all occurrences of 2 or more spaces by a single space.
sFirstLine = sFirstLine.replace(/ +/g," ");
// Split the first line up into an array of strings at every space.
var asNumbers = sFirstLine.split(' ');
var sResult = "";
for (var nNumber = 0; nNumber < asNumbers.length; nNumber++)
{
// Ignore empty strings and strings not starting with a digit.
if (!asNumbers[nNumber].length) continue;
if ((asNumbers[nNumber][0] < '0') || (asNumbers[nNumber][0] > '9')) continue;
// Use match function of String object to find out how often
// each string in first line exists in total on all lines.
var rSearch = new RegExp(asNumbers[nNumber], 'g');
var asFound = sAllLines.match(rSearch);
// Build the output string.
if (nNumber > 0) sResult += "\n";
sResult += asNumbers[nNumber] + " = " + asFound.length;
}
// Print the results into the output window.
UltraEdit.outputWindow.clear();
UltraEdit.outputWindow.showStatus=false;
if (UltraEdit.outputWindow.visible == false)
{
UltraEdit.outputWindow.showWindow(true);
}
UltraEdit.outputWindow.write(sResult);
}
}
}
Numbers are like 01 03 05 07 08 09 10 15 28 34 38 42 47 51 ... 99 00 (each line ends with an enter).
Real result (limited to 50 numbers, and should be 100):
Code: Select all
01 = 3003
02 = 3003
03 = 3003
04 = 3003
05 = 3003
06 = 3003
11 = 5598
12 = 4402
15 = 4987
16 = 4576
17 = 5662
19 = 3806
24 = 3898
26 = 5160
27 = 6330
28 = 4484
29 = 2854
31 = 3531
37 = 5314
38 = 6012
39 = 5307
41 = 5670
43 = 5656
47 = 5600
48 = 5625
49 = 6350
50 = 4866
51 = 5530
54 = 4899
55 = 4756
58 = 3969
61 = 4675
62 = 4987
63 = 4592
64 = 5335
67 = 2694
68 = 3884
73 = 5324
74 = 4290
76 = 5555
77 = 2540
78 = 4474
85 = 5488
86 = 5007
87 = 5409
89 = 2872
90 = 2584
92 = 6203
97 = 6538
98 = 5266