home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB11.ZIP / CENTREPL.INC < prev    next >
Encoding:
Text File  |  1985-07-13  |  2.7 KB  |  64 lines

  1. {
  2. Functions REPLICATE and CENTER
  3. Source: "Programming Quickies", TUG Lines Volume I Issue 3
  4. Author: Jim Nutt
  5. Application: All systems
  6. }
  7.  
  8. Type
  9.   Menu_Item       = String[40];
  10.   Menu_Selections = Array[1..15] of Menu_Item;
  11.   Long_String     = String[255];
  12.  
  13. {$V- Loosen up type checking for these routines}
  14.                                               {******************************}
  15. Function Replicate (                          {* Repeat a character         *}
  16.                      Count : Integer;         {* Number of Repititions      *}
  17.                      Ascii : Char             {* Character to be repeated   *}
  18.                    )       : Long_String;     {* String containing repeated *}
  19.                                               {* character                  *
  20.  ***********************************************                            *
  21.  * This function takes the character in 'Ascii', repeats it 'Count' times   *
  22.  * and returns the resulting string as a 'Long_String'                      *
  23.  ****************************************************************************}
  24.  
  25. Var
  26.   Temp : Long_String;  {Used to hold the incomplete result}
  27.   I    : Byte;         {For Counter}
  28.  
  29. Begin
  30.   Temp := '';
  31.   For I := 1 to Count do
  32.     Temp := Temp + Ascii;
  33.   Replicate := Temp;
  34. End; {Replicate}
  35.                                                {*****************************}
  36. Function Center (                              {* Centers a string in field *}
  37.                   Field_Width   : Byte;        {* Width of field for center *}
  38.                   Center_String : Long_String  {* String to Center          *}
  39.                 )               : Long_String; {* Return the string         *}
  40. {************************************************                           *
  41.  * This functions takes the string 'Center_String' and centers it in a      *
  42.  * field 'Field_Width' Spaces long.  It returns a 'Long_String' with a      *
  43.  * length equal to 'Field_Width'.  If the 'Center_String' is longer than    *
  44.  * field width, it is truncated on the right end and is not centered.       *
  45.  ****************************************************************************}
  46.  
  47. Var
  48.   Temp   : Long_String;
  49.   Middle : Byte;
  50.  
  51. Begin
  52.   Middle := Field_Width div 2;
  53.   If Length(Center_String) > Field_Width then
  54.     Center := Copy(Center_String,1,Field_Width) {Truncate and return}
  55.   Else
  56.     Begin
  57.     Temp := Replicate(Middle - (Length(Center_String) div 2),' ') +
  58.             Center_String +
  59.             Replicate(Middle - (Length(Center_String) div 2) + 1,' ');
  60.     Center := Copy(Temp, 1, Field_Width)  {Truncate to Field_Width Characters}
  61.     End {Else}
  62.  End; {Center}
  63. {$V+}
  64.