VB.NET tutorial-Count upper lower case letters in string

String Manipulation

Count upper lower case letters in string

You can use the IsUpper(char c) or IsLower(char c) methods to check a character if it is an upper case or it is a lower case letter.


Module Module1

Sub Main()

  Dim st As String = "Visual Basic Programming"
  Dim arr() As Char = st.ToCharArray()
  Dim countupper As Integer = 0
  Dim countlower As Integer = 0
  Dim i As Integer

  For i = 0 To arr.Length - 1
    If Char.IsUpper(arr(i)) Then
      countupper = countupper + 1
    ElseIf Char.IsLower(arr(i)) Then
       countlower = countlower + 1
    End If


  Console.WriteLine("Number of upper case letters:" & countupper)
  Console.WriteLine("Number of lower case letters:" & countlower)


End Sub

End Module


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.