Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,923 questions

51,856 answers

573 users

How to count strings and integers from an array of strings in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Friend Shared countnum As Integer = 0, countstr As Integer = 0

    Friend Shared Sub count_strings_and_integers(ByVal arr As String())
        Dim len As Integer = arr.Length

        For i As Integer = 0 To len - 1
            Try
                Dim num As Integer = Integer.Parse(arr(i))
                countnum += 1
            Catch __unusedFormatException1__ As System.FormatException
                countstr += 1
            End Try
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim arr As String() = New String() {"java", "888", "9", "c", "python", "109", "c++"}
        
		count_strings_and_integers(arr)
	
		Console.WriteLine("Numbers: " & countnum & Environment.NewLine & "Strings: " & countstr)
    End Sub
End Class



' run:
' 
' Numbers: 3
' Strings: 4
'

 



answered Feb 17, 2024 by avibootz
...