home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / wct / strings.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-12-31  |  1.5 KB  |  74 lines

  1. unit strings;
  2.  
  3. { Written by William C. Thompson }
  4.  
  5. { This unit was written to do a few basic things with strings }
  6.  
  7. interface
  8.  
  9. function allup(s:string):string;
  10. function lowcase(c:char):char;
  11. function alllow(s:string):string;
  12. function rep(s:string; n:integer):string;
  13. function leftpad(s:string; n:byte):string;
  14. procedure reverse(var s:string);
  15. procedure spacechop(var s:string);
  16.  
  17. implementation
  18.  
  19. function allup(s:string):string;
  20. var i:byte;
  21. begin
  22.   for i:=1 to length(s) do s[i]:=upcase(s[i]);
  23.   allup:=s
  24. end;
  25.  
  26. function lowcase(c:char):char;
  27. begin
  28.   if c in ['A'..'Z'] then c:=chr(ord(c)+32);
  29.   lowcase:=c
  30. end;
  31.  
  32. function alllow(s:string):string;
  33. var i:byte;
  34. begin
  35.   for i:=1 to length(s) do s[i]:=lowcase(s[i]);
  36.   alllow:=s
  37. end;
  38.  
  39. function rep(s:string; n:integer):string;
  40. var
  41.   t: string;
  42.   i: integer;
  43. begin
  44.   t:='';
  45.   for i:=1 to n do t:=t+s;
  46.   rep:=t
  47. end;
  48.  
  49. function leftpad(s:string; n:byte):string;
  50. { pads a string < length n with spaces on the left to make length n }
  51. begin
  52.   if length(s)>=n then leftpad:=s
  53.   else leftpad:=rep(' ',n-length(s))+s
  54. end;
  55.  
  56. procedure reverse(var s:string);
  57. var
  58.   t: string;
  59.   l,i: integer;
  60. begin
  61.   l:=length(s);
  62.   t:=s;
  63.   for i:=l downto 1 do t[l+1-i]:=s[i];
  64.   s:=t
  65. end;
  66.  
  67. procedure spacechop(var s:string);
  68. { chops leading and trailing spaces from s }
  69. begin
  70.   while (length(s)>0) and (s[1]=' ') do delete(s,1,1);
  71.   while (length(s)>0) and (s[length(s)]=' ') do delete(s,length(s),1);
  72. end;
  73.  
  74. end.