vb.net

count total number of space in a string vb.net

In this article we will see how to count total number of space in a string vb.net ?

Code for count total number of space in a string vb.net

Imports System

Namespace ConsoleApp1
Class Program
Private Shared Sub Main(ByVal args As String())
Dim spcctr As Integer = 0
Dim str1 As String
Dim str2 As String
Console.Write("Please input a string : ")
str2 = Console.ReadLine()

For i As Integer = 0 To str2.Length - 1
str1 = str2.Substring(i, 1)
If str1 = " " Then spcctr += 1
Next

Console.Write("----------------------------------------------------" & vbLf)
Console.WriteLine("""" & str2 & """" & " contains {0} spaces", spcctr)
Console.ReadLine()
End Sub
End Class
End Namespace

 

Output :

count-total-number-of-space-in-a-string-vb-net

Leave a Reply

Your email address will not be published. Required fields are marked *