thoga31

Challenge 9 (VB.NET)

Aug 13th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.88 KB | None | 0 0
  1. Module Module1
  2.     Sub Main()
  3.         Dim file_name As String = "challenge9_list.txt"
  4.         Dim f As New IO.StreamReader(file_name)
  5.         Dim ch As Char
  6.         Dim sumdigit As UInt16 = 0
  7.         Dim alpha() As UInt16 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  8.  
  9.         While Not f.EndOfStream
  10.             ch = f.ReadLine()(0)
  11.             If Char.IsDigit(ch) Then
  12.                 sumdigit += Convert.ToInt16(ch)
  13.             ElseIf Char.IsLetter(ch) Then
  14.                 alpha(Asc(ch) - Asc("a"c)) += 1
  15.             End If
  16.         End While
  17.  
  18.         Console.WriteLine("Sum = {0}", sumdigit)
  19.         For i As UInt16 = 0 To alpha.Length - 1
  20.             If alpha(i) <> 0 Then
  21.                 Console.WriteLine("'{0}' = {1}", Chr(i + Asc("a"c)), alpha(i))
  22.             End If
  23.         Next
  24.  
  25.         Console.ReadKey(True)
  26.     End Sub
  27. End Module
Advertisement
Add Comment
Please, Sign In to add comment