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,866 questions

51,788 answers

573 users

How to check if two strings have the same words in different order with VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Function two_strings_have_same_words_in_different_order(ByVal str1 As String, ByVal str2 As String) As Boolean
        If str1.Length <> str2.Length Then
            Return False
        End If

        Dim arr1 As String() = str1.Split(" "c)
        Dim wordsOfStr1 As List(Of String) = New List(Of String)(arr1)
        Dim wordsOfStr2 As String() = str2.Split(" "c)

        For i As Integer = 0 To wordsOfStr2.Length - 1
            If Not wordsOfStr1.Contains(wordsOfStr2(i)) Then Return False
        Next

        Return True
    End Function

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

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

 
 
 
' run:
'
' yes
'

 



answered May 9, 2024 by avibootz
...