How to count the total number of punctuation characters in a string with VB.NET

1 Answer

0 votes
Imports System
 
Public Class Program
    Public Shared Sub Main()
        Dim str As String = "Visual Basic .NET, is object-oriented programming language."
         
        Dim count As Integer = 0
        For i As Integer = 0 To str.Length - 1
            If str(i) = "."c OrElse str(i) = ","c OrElse str(i) = "!"c OrElse str(i) = ";"c _
                OrElse str(i) = "?"c OrElse str(i) = "-"c OrElse str(i) = "'"c _
                OrElse str(i) = """"c OrElse str(i) = ":"c Then
                count += 1
            End If
        Next
 
        Console.WriteLine(count)
    End Sub
End Class
 
 
 
 
' run:
'
' 4
'

 



answered Sep 27, 2021 by avibootz
edited Sep 27, 2021 by avibootz
...