Re: About word frequency
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Fri, 18 Sep 2009 05:26:34 -0700 (PDT)
On Sep 18, 6:02 am, "Pegasus [MVP]" <n...@xxxxxxxxxxxxx> wrote:
"buddy" <buddy....@xxxxxxxxx> wrote in message
news:4d0e4a2d-9d06-4722-bd64-a38939775861@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
To All:
Is it possible to count word frenquecy?I have lots of text file that
have so many duplicate phone numbers, I used regular expression to
filter all the phone num in a list, how to perfom word frequency
counting by using vbs?Thanks!
I always chuckle when posters ask "Is it possible to . . ." and I'm tempted
to say "Yes, it is possible!". I suspect that this is not really what you
want to know, so here is a suggestion:
1. Put your phone numbers into a string, separated by a suitable divider,
e.g. like so:
059 229 8732?034 887 9912?012 555 3964
2. Use the split function to turn the string into an array.
3. Sort the array.
4. Count the number of occurances of each unique number.
Yes, that's one way to do it, but that requires manual post-processig
(which I hate). Further, I suspect that the real desire (unexpressed)
is to extract a list of unique numbers. For that, I'd use a
dictionary, something like this ...
With CreateObject("Scripting.FileSystemObject")
aList = Split(.OpenTextFile("file1.txt", 1).ReadAll, vbNewLine)
end With
Set dUnique = CreateObject("Scripting.Dictionary")
For each sLine in aList
sline = trim(sline)
if sline <> "" Then
if dUnique.Exists(sLine) then
dUnique(sLine) = dUnique(sLine) + 1
else
dUnique(sLine) = 1
end if
end if
Next
for each k in dUnique.keys
wsh.echo k, dUnique.item(k)
next
Actually, this returns the unique items and their count. Note that it
does not sort the list.
_____________________
Tom Lavedas
.
- Follow-Ups:
- Re: About word frequency
- From: buddy
- Re: About word frequency
- From: Pegasus [MVP]
- Re: About word frequency
- References:
- About word frequency
- From: buddy
- Re: About word frequency
- From: Pegasus [MVP]
- About word frequency
- Prev by Date: Re: Convert Vb code to VBscript
- Next by Date: Re: About word frequency
- Previous by thread: Re: About word frequency
- Next by thread: Re: About word frequency
- Index(es):
Relevant Pages
|
Loading