Documentation
Back to website >

CompareText (Pascal-Script)

Description

CompareText compares two strings on the basis of their ordinal value without consideration of upper and lower case.

CompareText compares S1 with S2 and returns 0 if both are identical. If S1 is greater than S2, an integer value greater than 0 is returned. If S1 is less than S2, the return value is less than 0; the comparison is not case-sensitive and does not take the current Windows country setting into account.

For example, CompareText specifies that the string
ABC
is smaller than
aaa
because A is smaller than a in the ASCII order. This is in contrast to a case-insensitive comparison. In this case, the letter B or a comparison based on the country setting (in most language drivers, uppercase letters have higher values than lowercase letters) would display the first string as larger.

Syntax

function CompareText(const S1, S2: String): Integer;

Arguments

S1 is the first text to be compared, S2 is the second text to be compared with the first text.

Example

var
  S1: String;
  S2: String;
  i:Integer;
  S3: String;
begin
  S1:='Berta';
  S2:='Mark';
  i:=CompareText(S1,S2);
  S3:=IntToStr(i);
  ShowMessage(S3);
end;

Rules to understand the script can be found here.

In this example, texts S1 and S2 are compared with each other. The function CompareText generates a negative integer value if the content of S1 is smaller, a positive integer value if it is larger, and 0 if it is equal. The result of CompareText is assigned to the integer variable i, which is then converted to text S3 via IntToStr and output via ShowMessage. The result is expected to be negative, as S1 is smaller than S2.

ShowMessage shows: -11