Exercise
Count words
Objetive
Create a Visual Basic (VB.Net) program to count the amount of words stored in a text file
Code
Imports System
Imports System.IO
Class Program
Private Shared Sub Main(ByVal args As String())
Dim file As StreamReader = File.OpenText("1.cs")
Dim line As String
Dim amountOfWords As Integer = 0
Do
line = file.ReadLine()
If line IsNot Nothing Then
Dim words As String() = line.Split(" "c)
amountOfWords += words.Length
End If
Loop While line IsNot Nothing
file.Close()
Console.WriteLine("Words: " & amountOfWords)
End Sub
End Class