-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordcount.vb
35 lines (29 loc) · 957 Bytes
/
wordcount.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Imports System.Text.RegularExpressions
Module WordCount
Dim records As New Dictionary(Of String, Integer)
Sub CountInFile(ByRef file As IO.FileInfo)
Dim content = IO.File.ReadAllText(file.FullName)
Dim words = Regex.Split(content, "\s+")
For Each word In words
If records.ContainsKey(word) Then
records.Item(word) += 1
Else
records.Item(word) = 1
End If
Next
End Sub
Sub WalkDir(ByRef directory As IO.DirectoryInfo)
For Each file In directory.GetFiles
CountInFile(file)
Next
For Each subDir In directory.GetDirectories
WalkDir(subDir)
Next
End Sub
Sub Main()
WalkDir(New IO.DirectoryInfo("./testdata"))
For Each kv As KeyValuePair(Of String, Integer) In records
Console.WriteLine($"{kv.Key} {kv.Value}")
Next
End Sub
End Module