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
|
|
|
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.
| Show full unit code | ABC compared to DEF = -1
ABC compared to ABC = 0
DEF compared to ABC = 1
|
|
|
|