home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / explorer / strutils.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  1.4 KB  |  71 lines

  1. unit Strutils;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: EXPLORER }
  5.  
  6. interface
  7.  
  8. function LeftSet(src: String; Width: Integer; var Trunc: Boolean): String;
  9. function GetFirstWord(S : String) : String;
  10. function StripSpaces(S : String) : String;
  11. function AddBackSlash(S: String): String;
  12.  
  13. implementation
  14.  
  15. uses SysUtils;
  16.  
  17. function LeftSet(src: String; Width: Integer; var Trunc: Boolean): String;
  18. { Pads a string on the left }
  19. var
  20.   I : Integer;
  21. begin
  22.   Trunc := False;
  23.   Result := src;
  24.   if(Length(Result) > Width) and (Width > 0) then begin
  25.     Result[0] := CHR(Width);
  26.     Trunc := True;
  27.   end
  28.   else
  29.     for i := Length(Result) to width do
  30.       Result := Result + ' ';
  31. end;
  32.  
  33. function GetFirstWord(S : String) : String;
  34. { Returns the first word from a string }
  35. Var
  36.   i : Integer;
  37. begin
  38.   i := 1;
  39.   Result := S;
  40.   while (Result[i] <> ' ') and (i < Length(S)) do begin
  41.      Result[i] := S[i];
  42.      Inc(i);
  43.   end;
  44.   Dec(i);
  45.   Result[0] := Chr(i);
  46. end;
  47.  
  48. function AddBackSlash(S: String): String;
  49. begin
  50.   Result := S;
  51.   if S[Length(S)] <> '\' then
  52.     AppendStr(Result, '\');
  53. end;
  54.  
  55. function StripSpaces(S: String): String;
  56. { Strips all spaces out of a string }
  57. var
  58.   i: Integer;
  59. begin
  60.   i := 1;
  61.   repeat
  62.     if S[i] = ' ' then
  63.       Delete(S, i, 1)
  64.     else
  65.       inc(i);
  66.   until i > Length(S);
  67.   Result := S;
  68. end;
  69.  
  70. end.
  71.