ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the Equals() method of String class

Here, we are going to demonstrate the Equals() method of String class in VB.Net.
Submitted by Nidhi, on January 20, 2021

The Equals() method is used to check the equality of two strings and return a Boolean value.

Syntax:

Function Equals(ByVal str1 as String, ByVal str2 as String) as Boolean

Parameters:

  • Str1: String to be compared.
  • Str2: String to be compared.

Return Value: It returns a boolean value, if both strings are equal then it will return true otherwise it will return false.

Program/Source Code:

The source code to demonstrate the Equals() method of the String class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the Equals() method 
'of String class.

Imports System

Module Module1
    Sub Main()
        Dim str1 As String = "hello World"
        Dim str2 As String = "Hello World"
        Dim str3 As String = "Hello World"

        Dim ret As Boolean

        ret = String.Equals(str1, str2)
        If ret = True Then
            Console.WriteLine("Strings str1 and str2 are equal")
        Else
            Console.WriteLine("Strings str1 and str2 are not equal")
        End If

        ret = String.Equals(str2, str3)
        If ret = True Then
            Console.WriteLine("Strings str2 and str3 are equal")
        Else
            Console.WriteLine("Strings str2 and str3 are not equal")
        End If
    End Sub
End Module

Output:

Strings str1 and str2 are not equal
Strings str2 and str3 are equal
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created three strings str1, str2, and str3. Here, we compared the values of strings using the Equals() method of the String class. This method returns true when the values of specified strings are equal otherwise it will return a false value. Here, we printed the appropriate message according to string values on the console screen.

VB.Net String Programs »



ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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.