Janilabo

Janilabo | Compare2() [Simba]

Jun 20th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.96 KB | None | 0 0
  1. function Compare2(s1, s2: string): Integer;
  2. var
  3.   i, mL, s1L, s2L: Integer;
  4. begin
  5.   if s1 = s2 then
  6.     Exit;
  7.   s1L := Length(s1);
  8.   s2L := Length(s2);
  9.   if (s1L <= 0) or (s2L <= 0) then
  10.     if (s1L < s2L) then
  11.       Result := -1
  12.     else
  13.       Result := 1;
  14.   if (Result <> 0) then
  15.     Exit;
  16.   Result := -1;
  17.   mL := Min(s1L, s2L);
  18.   for i := 1 to mL do
  19.     if (s1[i] <> s2[i]) then
  20.     begin
  21.       if (s1[i] > s2[i]) then
  22.         Result := 1;
  23.       Exit;
  24.     end;
  25.   if (s1L > s2L) then
  26.     Result := 1;
  27. end;
  28.  
  29. function GetRelation(s1, s2: string): string;
  30. var
  31.   r: Integer;
  32. begin
  33.   r := Compare2(s1, s2);
  34.   case r of
  35.     -1: Result := ('"' + s1 + '" < "' + s2 + '"');
  36.     0: Result := ('"' + s1 + '" = "' + s2 + '"');
  37.     1: Result := ('"' + s1 + '" > "' + s2 + '"');
  38.   end;
  39. end;
  40.  
  41. begin
  42.   ClearDebug;
  43.   WriteLn(GetRelation('ABCD A', 'ABCD B'));
  44.   WriteLn(GetRelation('ABCD B', 'ABCD B'));
  45.   WriteLn(GetRelation('ABCD C', 'ABCD B'));
  46. end.
Advertisement
Add Comment
Please, Sign In to add comment