OK, this is a pretty basic example -- the way you parse words and sentences can be way more complex -- but it is a starting point...
Imports System.IO
Imports System.Text
Public Class FileCounts
Private \_text As String
Private \_name As String
Private \_sentences As Integer
Private \_words As Integer
Private \_characters As Integer
Public ReadOnly Property Sentences()
Get
Return \_sentences
End Get
End Property
Public ReadOnly Property Words()
Get
Return \_words
End Get
End Property
Public ReadOnly Property Characters()
Get
Return \_characters
End Get
End Property
Public Sub New(ByVal filename As String)
If File.Exists(filename) Then
\_name = filename
\_readFile()
\_characters = \_text.Length
\_sentences = \_text.Split(".").Length
\_words = \_text.Split(" ").Length
Else
Throw New ApplicationException("File " + filename + " does not exist")
End If
End Sub
Private Sub \_readFile()
Dim sb As StringBuilder = New StringBuilder
Try
Dim fs As FileStream = File.Open(\_name, FileMode.Open, FileAccess.Read, FileShare.None)
Dim b(1024) As Byte
Dim temp As UTF8Encoding = New UTF8Encoding(True)
While fs.Read(b, 0, b.Length) > 0
sb.Append(temp.GetString(b))
End While
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
\_text = sb.ToString()
End Sub
End Class
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.