Janilabo

Janilabo | Compare() [SCAR Divi]

Apr 28th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.91 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Compares s1 with s2.
  3.                Results: 0=EQUAL, 1=s1>s2, -1=s1<s2                  
  4. [==============================================================================}
  5. function Compare(s1, s2: string): Integer;
  6. begin
  7.   case (s1 <> s2) of
  8.     True:
  9.     case (s1 > s2) of
  10.       True: Result := 1;
  11.       False: Result := -1;
  12.     end;
  13.     False: Result := 0;    
  14.   end;
  15. end;
  16.  
  17. function GetRelation(s1, s2: string): string;
  18. var
  19.   r: Integer;
  20. begin
  21.   r := Compare(s1, s2);
  22.   case r of
  23.     -1: Result := ('"' + s1 + '" < "' + s2 + '"');
  24.     0: Result := ('"' + s1 + '" = "' + s2 + '"');
  25.     1: Result := ('"' + s1 + '" > "' + s2 + '"');
  26.   end;
  27. end;
  28.  
  29. begin
  30.   ClearDebug;
  31.   WriteLn(GetRelation('ABCD A', 'ABCD B'));
  32.   WriteLn(GetRelation('ABCD B', 'ABCD B'));
  33.   WriteLn(GetRelation('ABCD C', 'ABCD B'));
  34. end.
Advertisement
Add Comment
Please, Sign In to add comment