Home  |  Delphi .net Home  |  System.String  |  Equals Method
Equals  
Method  
Determines whether two String objects have the same value.
String Class
System NameSpace
CF1.  Function Equals ( Value : String; ) : Boolean ;
CF2.  Function Equals ( Value : TObject; ) : Boolean ;
CF3.  Function Equals ( ValueA:StringValueA : String; ValueB : String; ) : Boolean;
CF4.  Function Equals ( ValueA:TObjectValueA : TObject; ValueB : TObject; ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns true if the two strings have exactly the same value. It is case sensitive.
 
Strings are objects in .Net (even though they are not implicitly created). Flavours 1 and 2 of the Equals method are methods of a string object.
 
Flavours 3 and 4 are static methods of the String class - meaning that you run the method standalone rather than against a string object. In this case, the two strings (or string objects) are passed as parameters.
Microsoft MSDN Links
System
System.String
 
 
Comparing one string with another
program Project1;
{$APPTYPE CONSOLE}

var
  a, b : String;
begin
  a := '12345';
  b := '123';

  if a.Equals(b)
  then Console.WriteLine('Match')
  else Console.WriteLine('No match');

  b := b + '45';

  if a.Equals(b)
  then Console.WriteLine('Match')
  else Console.WriteLine('No match');

  Console.ReadLine;
end.
Show full unit code
  No match
  Match
Comparing two strings using the static Equals method
program Project1;
{$APPTYPE CONSOLE}

var
  a, b : String;
begin
  a := '12345';
  b := '123';

  if System.String.Equals(a, b)
  then Console.WriteLine('Match')
  else Console.WriteLine('No match');

  b := b + '45';

  if System.String.Equals(a, b)
  then Console.WriteLine('Match')
  else Console.WriteLine('No match');

  Console.ReadLine;
end.
Show full unit code
  No match
  Match
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author