How to check if two strings have the same number of words in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
    Public Shared Function two_strings_have_same_number_of_words(ByVal str1 As String, ByVal str2 As String) As Boolean
        Dim wordsOfStr1 As List(Of String) = str1.Split(" ").ToList()
        Dim wordsOfStr2 As List(Of String) = str2.Split(" ").ToList()
		
        Return wordsOfStr1.Count = wordsOfStr2.Count
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim str1 As String = "c# vb java rust"
        Dim str2 As String = "c c++ python go"

        If two_strings_have_same_number_of_words(str1, str2) Then
            Console.WriteLine("yes")
        Else
            Console.WriteLine("no")
        End If
    End Sub
End Class

 
 
 
' run:
'
' yes
'

 



answered May 9, 2024 by avibootz
...