home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / mp3osr05.zip / src / trims.inc < prev    next >
Text File  |  1999-12-07  |  1KB  |  73 lines

  1. (*
  2.  * part of MPEG searcher project
  3.  *  (c) 1999 by Alexander Trunov, 2:5069/10, jnc@mail.ru
  4.  *)
  5.  
  6. function  LTrim (const victim: string): string;
  7. var
  8.   i: Integer;
  9. begin
  10.   Result := victim;
  11.   i := 1;
  12.   while i <= Length (Result) do
  13.   begin
  14.     if Result [i] in [' ', #09] then
  15.       Delete (Result, i, 1)
  16.     else
  17.       Exit;
  18.   end;
  19. end;
  20.  
  21. function  RTrim (const victim: string): string;
  22. var
  23.   i: Integer;
  24. begin
  25.   Result := victim;
  26.   i := Length (Result);
  27.   while i >= 1 do
  28.   begin
  29.     if Result [i] in [' ', #09] then
  30.       Delete (Result, i, 1)
  31.     else
  32.       Exit;
  33.     dec (i);
  34.   end;
  35. end;
  36.  
  37. function  Trim (const victim: string): string;
  38. begin
  39.   Result := RTrim (LTrim (victim));
  40. end;
  41.  
  42. procedure TrimEx(var victim: string);
  43. begin
  44.   victim := Trim(victim);
  45. end;
  46.  
  47. function BinaryB(B: Byte): string; // from TPString
  48. const
  49.   Digits: array [0..15] of Char = '0123456789abcdef';
  50. var
  51.   I, N: Word;
  52. begin
  53.   N := 1;
  54.   Result[0] := #8;
  55.   for I := 7 downto 0 do begin
  56.     Result[N] := Digits[Ord(B and (1 shl I) <> 0)];
  57.     inc(N);
  58.   end;
  59. end;
  60.  
  61. function Bin2Long(s: String): Longint;
  62. var
  63.   x: Integer;
  64.   r, p: Longint;
  65. begin
  66.   Result := 0;
  67.   p := 1;
  68.   for x := Length(s) downto 1 do
  69.   begin
  70.     if s[x] = '1' then Result := Result + p;
  71.     p := p * 2;
  72.   end;
  73. end;