Home >>VB.Net Programs >VB.Net program to compare two strings

VB.Net program to compare two strings

Write a VB.Net program to compare two strings

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

Program :

Here is the source code for comparing the two strings. The program given is compiled and successfully executed.

Example


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

Explanation:

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

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

We use statements in the above code to compare two strings, and then we print a suitable message on the console screen.


VB.Net Programs Program to Print Hello World in VB.NET VB.Net program to demonstrate the difference between Console.Write() and Console.WriteLine() methods VB.Net program to print backslash (\) character on the console screen VB.Net program to convert a double number into an integer number VB.Net program to convert different types of variables into the string VB.Net program to demonstrate the use of the 'vbTab' constant VB.Net program to demonstrate the use of the 'vbCrLf' constant VB.Net program to input and print an integer variable VB.Net program to demonstrate the bitwise operators VB.Net program to print the binary number of a decimal number VB.Net program to print the total bits required to store a given integer number VB.Net program to count the total number of high bits in a given integer number VB.Net program to demonstrate the left-shift operator (<<) VB.Net program to demonstrate the right-shift operator (>>) VB.Net Program to perform BITWISE AND operation VB.Net program to perform BITWISE OR operation VB.Net program to perform BITWISE XOR operation VB.Net program to demonstrate the BITWISE NOT operator VB.Net program to perform the LOGICAL AND operation using the AndAlso operator VB.Net program to perform the LOGICAL OR operation using the OrElse operator VB.Net program to check the palindrome of the binary number using bitwise operators VB.Net program to check the given number is even or odd VB.Net program to check EVEN/ODD using bitwise operators VB.Net program to swap two numbers using a BITWISE XOR operator VB.Net program to check Nth bit of an integer number is SET or not VB.Net program to check the given number is EVEN or ODD using conditional operator VB.Net program to find the largest number between two numbers VB.Net program to find the largest number among three numbers VB.Net program to check the given number is POSITIVE or NEGATIVE VB.Net program to check leap year VB.Net program to check the given year is leap year or not using conditional operator VB.Net program to calculate the area of the circle VB.Net program to calculate the perimeter of the circle VB.Net program to calculate the area of the rectangle VB.Net program to calculate the Highest Common Factor (HCF) VB.Net program to calculate the multiplication of two numbers using the '+' operator VB.Net program to round off the value of the floating-point number VB.Net program to get a large value using Math.Max() method VB.Net program to get the smallest value using Math.Min() method VB.Net program to produce the full product of two 32-bit integer numbers VB.Net program to truncate the value of the floating-point number VB.Net program to find the angle for specified sine value VB.Net program to find the angle for specified cosine value VB.Net program to find the angle for specified tangent value VB.Net program to find the sine value for the specified angle VB.Net program to find the cosine value for the specified angle VB.Net Program to find the tangent value for the specified angle VB.Net program to find the hyperbolic sine VB.Net program to find the hyperbolic cosine VB.Net program to find the hyperbolic tangent VB.Net Program to demonstrate the Math.DivRem() method VB.Net program to demonstrate the Math.Exp() method VB.Net program to demonstrate the use of Math.IEEERemainder() method VB.Net program to find the logarithm value of a specified number VB.Net program to demonstrate the Math.Log10() method VB.Net program to find the sign of a specified number using Math.Sign() method VB.Net program to find the division of a student based on a given percentage VB.Net program to compare two strings VB.Net program to demonstrate the use of 'select case' VB.Net program to demonstrate the use of 'select case' with a given range VB.Net program to use a comma ',' to use multiple options in 'select case' VB.Net program to demonstrate the nested 'select case' VB.Net program to demonstrate the duplicate case in the 'select case' VB.Net program to create a simple calculator using 'select case' VB.Net program to print the table of given number using GoTo statement VB.Net program to print the ASCII values of numbers VB.Net program to print the HEX values of numbers VB.Net program to print 1, 11, 31, 61, ..., 10 times using GoTo statement VB.Net program to read a name and print 5 times using GoTo statement VB.Net program to print the square of numbers from 1 to 5