Re: About word frequency



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
.



Relevant Pages

  • sort 1-D array of doubles for Olaf Schmidt
    ... A few weeks Olaf Schmidt posted a VB6 routine to sort a 1-D array of strings very fast indeed. ... fastest way to change case of string. ... Dim i As Long, j As Long, Lo As Long, Hi As Long, StPtr As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Collection Structure
    ... property StringID you want ... where inarr is the String array and outarr is an array of longs containing ... needs to sort the input array keeping track of the original position (I use ...
    (microsoft.public.vb.com)
  • Re: Quick method to sort a list of strings?
    ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
    (microsoft.public.excel.programming)
  • RE: Quick method to sort a list of strings?
    ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
    (microsoft.public.excel.programming)
  • Re: About word frequency
    ... Use the split function to turn the string into an array. ... Sort the array. ... For each sLine in aList ... In Step 5 I was actually thinking of counting the various strings with VB ...
    (microsoft.public.scripting.vbscript)

Loading