home *** CD-ROM | disk | FTP | other *** search
- {
- Functions REPLICATE and CENTER
- Source: "Programming Quickies", TUG Lines Volume I Issue 3
- Author: Jim Nutt
- Application: All systems
- }
-
- Type
- Menu_Item = String[40];
- Menu_Selections = Array[1..15] of Menu_Item;
- Long_String = String[255];
-
- {$V- Loosen up type checking for these routines}
- {******************************}
- Function Replicate ( {* Repeat a character *}
- Count : Integer; {* Number of Repititions *}
- Ascii : Char {* Character to be repeated *}
- ) : Long_String; {* String containing repeated *}
- {* character *
- *********************************************** *
- * This function takes the character in 'Ascii', repeats it 'Count' times *
- * and returns the resulting string as a 'Long_String' *
- ****************************************************************************}
-
- Var
- Temp : Long_String; {Used to hold the incomplete result}
- I : Byte; {For Counter}
-
- Begin
- Temp := '';
- For I := 1 to Count do
- Temp := Temp + Ascii;
- Replicate := Temp;
- End; {Replicate}
- {*****************************}
- Function Center ( {* Centers a string in field *}
- Field_Width : Byte; {* Width of field for center *}
- Center_String : Long_String {* String to Center *}
- ) : Long_String; {* Return the string *}
- {************************************************ *
- * This functions takes the string 'Center_String' and centers it in a *
- * field 'Field_Width' Spaces long. It returns a 'Long_String' with a *
- * length equal to 'Field_Width'. If the 'Center_String' is longer than *
- * field width, it is truncated on the right end and is not centered. *
- ****************************************************************************}
-
- Var
- Temp : Long_String;
- Middle : Byte;
-
- Begin
- Middle := Field_Width div 2;
- If Length(Center_String) > Field_Width then
- Center := Copy(Center_String,1,Field_Width) {Truncate and return}
- Else
- Begin
- Temp := Replicate(Middle - (Length(Center_String) div 2),' ') +
- Center_String +
- Replicate(Middle - (Length(Center_String) div 2) + 1,' ');
- Center := Copy(Temp, 1, Field_Width) {Truncate to Field_Width Characters}
- End {Else}
- End; {Center}
- {$V+}