Comparing 2 strings is often used action in any programming language. You could want to compare two strings when you check if the username and password entered by user are correct. Also it could be very useful if you search some text.This C# ASP.NET tutorial with show you several methods to compare the values of strings.

Compare strings in ASP.NET

Compare strings in C# an VB.NET

– You could use the Compare method to determine the relative values of two strings. It will return 0 if the 2 strings are equals.

String.Compare(“www.windowshostingasp.net”, “www.windowshostingasp.net”);

– You could use the Compare method to determine the relative values of two strings. It will return the same values as Compare method.

String.CompareOrdinal(“www.howtoasp.net”, “www.howtoasp.net”);

– You could use the String.Equals method to determine if two strings are the same.

C#

string MyString = “www.windowshostingasp.net”;
Console.WriteLine(MyString.Equals(“www.windowshostingasp.net”));

VB.NET

Dim MyString As String = “www.windowshostingasp.net”
Console.WriteLine(MyString.Equals(“www.windowshostingasp.net”))