Home  |  Delphi .net Home  |  System.String  |  CompareTo Method
  
CompareTo  
Method  
Compares the current string with another
String Class
System NameSpace
CF1.  Function CompareTo ( Target : String ) : Integer;
CF2.  Function CompareTo ( Target : Object ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns one of the following values :
 
Source < Target Gives <0
Source = Target Gives ?0
Source > Target Gives >0

 
The exact value is not guaranteed.
 
The comparison is case sensitive and culture sensitive. Use Compare to perform a case insensitive comparison.
 
Lower case letters are deemed to be lower in value than upper case letters.
 
An empty string always precedes any other string.
 
The 2nd syntax requires the target object to evaluate to a string.
Microsoft MSDN Links
System
System.String
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA, strB : String;
  result     : Integer;

begin
  strA := 'ABC';
  strB := 'DEF';

  result := strA.CompareTo(strB);
  Console.WriteLine(strA + ' compared to ' + strB + ' = ' + result.ToString);

  result := strA.CompareTo(strA);
  Console.WriteLine(strA + ' compared to ' + strA + ' = ' + result.ToString);

  result := strB.CompareTo(strA);
  Console.WriteLine(strB + ' compared to ' + strA + ' = ' + result.ToString);

  Console.ReadLine;
end.
   ABC compared to DEF = -1
   ABC compared to ABC = 0
   DEF compared to ABC = 1
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author