Is there a script out there that will read a text file and then give totals
for each letter found, a-z

Re: Count Letters by Nic

Nic
Sun May 22 16:49:13 CDT 2005

>and then give totals for each letter found, a-z

Once you've loaded the text with the FileSystemObject, I expect the RegExp
object using the matches collection will be your best bet.

I think the expression would be:

^[a-z]$


Nic Roche

"JohnB" <jbrigan@yahoo.com> wrote in message
news:e2ev%23LxXFHA.2540@tk2msftngp13.phx.gbl...
> Is there a script out there that will read a text file and then give
> totals for each letter found, a-z
>
>



Re: Count Letters by Roland

Roland
Sun May 22 17:26:25 CDT 2005

"Nic Roche" <nicroche@hotmail.com> wrote in message
news:u4uy1dxXFHA.2080@TK2MSFTNGP15.phx.gbl...
: >and then give totals for each letter found, a-z
:
: Once you've loaded the text with the FileSystemObject, I expect the RegExp
: object using the matches collection will be your best bet.
:
: I think the expression would be:
:
: ^[a-z]$

To add...
You might want to convert everything to lower-case before testing or include
A-Z.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Re: Count Letters by Christoph

Christoph
Sun May 22 18:44:25 CDT 2005

22.05.2005 23:11, JohnB schrieb:
> Is there a script out there that will read a text file and then give totals
> for each letter found, a-z

var file = "testfile.txt";

var fs = new ActiveXObject ("Scripting.FileSystemObject");
var txt = fs.OpenTextFile(file);
var items = {}, arr = [];

while (!txt.AtEndOfStream) {
var c = txt.Read(1);
if (/[a-z]/i.test(c)) {
if (undefined == items[c]) {
items[c] = 1;
arr.push(c);
} else
items[c] += 1;
}
}

txt.Close();
arr.sort(ByHits);

var s = 'character-count in file\r\n';
s += file.substr(file.lastIndexOf('\\')+1);
s += '\r\nsorted desc by frequency\r\n\r\n';

for (var i=0; i<arr.length;i++) {
c = arr[i];
s += c + " -> " + items[c]+ '\r\n';
}

WScript.Echo(s);

function ByHits (i1, i2) {
if (items[i1] > items[i2]) return -1;
if (items[i1] < items[i2]) return 1;
return 0;
}

--
Gruesse, Christoph

Rio Riay Riayo - Gordon Sumner, 1979

Re: Count Letters by JohnB

JohnB
Mon May 23 17:00:14 CDT 2005

Thanks! That worked great.


"Christoph Basedau" <e_tonne@hotmail.com> wrote in message
news:42911995$0$25691$9b4e6d93@newsread2.arcor-online.net...
> 22.05.2005 23:11, JohnB schrieb:
>> Is there a script out there that will read a text file and then give
>> totals
>> for each letter found, a-z
>
> var file = "testfile.txt";
>
> var fs = new ActiveXObject ("Scripting.FileSystemObject");
> var txt = fs.OpenTextFile(file);
> var items = {}, arr = [];
>
> while (!txt.AtEndOfStream) {
> var c = txt.Read(1);
> if (/[a-z]/i.test(c)) {
> if (undefined == items[c]) {
> items[c] = 1;
> arr.push(c);
> } else
> items[c] += 1;
> }
> }
>
> txt.Close();
> arr.sort(ByHits);
>
> var s = 'character-count in file\r\n';
> s += file.substr(file.lastIndexOf('\\')+1);
> s += '\r\nsorted desc by frequency\r\n\r\n';
>
> for (var i=0; i<arr.length;i++) {
> c = arr[i];
> s += c + " -> " + items[c]+ '\r\n';
> }
>
> WScript.Echo(s);
>
> function ByHits (i1, i2) {
> if (items[i1] > items[i2]) return -1;
> if (items[i1] < items[i2]) return 1;
> return 0;
> }
>
> --
> Gruesse, Christoph
>
> Rio Riay Riayo - Gordon Sumner, 1979