VB.Net program to compare two strings

Here, we are going to learn how to compare two strings in VB.Net?
Submitted by Nidhi, on December 03, 2020

Here, we will read two strings and compare using equal to = operator and print the appropriate message on the console screen.

Program/Source Code:

The source code to compare two strings is given below. The given program is compiled and executed successfully.

'VB.Net program to compare two strings.

Module Module1

    Sub Main()
        Dim str1 As String
        Dim str2 As String

        Console.Write("Enter string1: ")
        str1 = Console.ReadLine()

        Console.Write("Enter string2: ")
        str2 = Console.ReadLine()

        If str1 = str2 Then
            Console.WriteLine("Strings are equal")
        Else
            Console.WriteLine("Strings are not equal")
        End If
    End Sub
    
End Module

Output:

Enter string1: Abc
Enter string2: abc
Strings are not equal
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a method Main(). In the Main() method, we created two string variables str1 and str2.

Console.Write("Enter string1: ")
str1 = Console.ReadLine()

Console.Write("Enter string2: ")
str2 = Console.ReadLine()

In the above code, we read two strings str1 and str2

If str1 = str2 Then
    Console.WriteLine("Strings are equal")
Else
    Console.WriteLine("Strings are not equal")
End If

In the above code we use if statements to compare two strings, and then we printed appropriate message on the console screen.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.