Help with program for counting using hashtable
-
I want to create a programm that would read data from a file and will put each distinct item in a hashtable,counting how often it appears.I want to count first how often single characters or numbers appear,then how often the combination of two characters appear,three characters etc. More specifically... How can I use hashtable to count the appearances of some items in a file.For example how often is the letter a used,letter b etc.I am using hashtable.class in java.util.* ,but what I can not do is associate each letter that I am reading with a place in the hashtable. For example the following code creates a hashtable called numbers with the default capacity and load factor.Then one-two-three are used as the keys and 1-2-3 as the values. Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); I want my hashtable to read a file one character or one number at a time and count their appearances. The data would most probably be in the form abc abcd a abce ecf e fg or 123 12346 12 348 7 2 3456 52 364725 Thanks a lot for suggestions to my previous question as well as to future ones. jkouris@hotmail.com
-
I want to create a programm that would read data from a file and will put each distinct item in a hashtable,counting how often it appears.I want to count first how often single characters or numbers appear,then how often the combination of two characters appear,three characters etc. More specifically... How can I use hashtable to count the appearances of some items in a file.For example how often is the letter a used,letter b etc.I am using hashtable.class in java.util.* ,but what I can not do is associate each letter that I am reading with a place in the hashtable. For example the following code creates a hashtable called numbers with the default capacity and load factor.Then one-two-three are used as the keys and 1-2-3 as the values. Hashtable numbers = new Hashtable(); numbers.put("one", new Integer(1)); numbers.put("two", new Integer(2)); numbers.put("three", new Integer(3)); I want my hashtable to read a file one character or one number at a time and count their appearances. The data would most probably be in the form abc abcd a abce ecf e fg or 123 12346 12 348 7 2 3456 52 364725 Thanks a lot for suggestions to my previous question as well as to future ones. jkouris@hotmail.com
const f = "C:\...\file.txt"
set fso = CreateObject("Scripting.FileSystemObject")
redim count(255)
set ts = fso.OpenTextFile(f)
do while not ts.AtEndOfStream
c = asc(ts.Read(1))
count(c) = count(c) + 1
loop
ts.close
set ts = fso.CreateTextFile(f & ".count")
ts.WriteLine "asc" & vbTab & "chr" & vbTab & "count"
for i = 0 to 255
if count(i) > 0 then ts.WriteLine i & vbTab & chr(i) & vbTab & count(i)
next
ts.closeinput: your mail output: asc chr count 10 (LF) 37 13 (CR) 37 32 176 34 " 6 40 ( 7 41 ) 7 42 * 1 44 , 8 45 - 4 46 . 19 49 1 5 50 2 8 51 3 7 52 4 4 53 5 3 54 6 3 55 7 2 56 8 1 59 ; 4 61 = 1 64 @ 1 70 F 2 72 H 3 73 I 10 77 M 1 84 T 3 97 a 102 98 b 24 99 c 39 100 d 20 101 e 115 102 f 20 103 g 12 104 h 47 105 i 38 106 j 2 107 k 3 108 l 38 109 m 25 110 n 57 111 o 61 112 p 22 113 q 1 114 r 53 115 s 52 116 t 94 117 u 31 118 v 3 119 w 23 120 x 2 121 y 6