Compare two strings for equality SysUtils unit
 function AnsiCompareStr ( const String1, String2 : string ) : Integer;
The AnsiCompareStr function compares String1 and String2 for equality.
This is the modern, Locale safe form of CompareStr.
All Ansi commands support multi-byte and accented characters.
It returns these values :
String1 < String2  : -ve number
String1 = String2  : 0
String1 > String2  : +ve number

The comparison is not affected by length - it is carried out on a letter by letter basis. But a longer string is greater than a shorter, otherwise matching string.
The comparison is case sensitive.
In Delphi :

Upper case letters > Lower case letters
Lower case letters > Numbers

Multi-byte character sets are operating system defined. For example, Oriental versions of Windows uses multi-byte characters to support their very large set of primitives ('letters').
Related commands
AnsiCompareText Compare two strings for equality, ignoring case
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Compare various strings
  // Compare two obviously different strings
  CompareStrings('HELLO', 'WORLD');

  // Compare identical strings
  CompareStrings('Hi 2 you', 'Hi 2 you');

  // Upper case letters follow lower case in Delphi
  CompareStrings('ABC', 'abc');

  // All letters follow numbers in Delphi
  CompareStrings('abc', '123');

// Compare two strings, and show which is bigger than the other
procedure TForm1.CompareStrings(const string1, string2: string);
  result : Integer;
  // Compare some strings
  result := AnsiCompareStr(string1, string2);

  if result < 0 then ShowMessage(string1+' < '+string2);
  if result = 0 then ShowMessage(string1+' = '+string2);
  if result > 0 then ShowMessage(string1+' > '+string2);
Show full unit code
   Hi 2 you = Hi 2 you
   ABC > abc
   abc > 123
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page