CentreChStr Function
Returns a string with specified characters added to the beginning and end of the string to in effect centre the string within the given length.

Unit
QESBPCSConvert

Declaration
Function CentreChStr(const S: string; const Ch: Char; const Len: LongWord): string;

Description
If even amounts of Ch cannot be put on both side, the extra Ch will be on the right side. Also See: CentreStr

Parameters
the string to be centred. If Length (S) >= Len then NO padding occurs, and S is returned.
Ch the character to Pad with.
Len the Length of returned string.

Category
Extra String Handling Routines

Implementation

function CentreChStr (const S: string; const Ch: Char;
     const Len: LongWord): string;
var
     N, M: LongWord;
begin
     N := Length (S);
     if N < Len then
     begin
          M := Len - N; // Length of padding needed
          N := M div 2; // Half on either side
          if Odd (M) then // Handle Odd differently to Even
               Result := FillStr (Ch, N) + S
                    + FillStr (Ch, N + 1)
          else
               Result := FillStr (Ch, N) + S
                    + FillStr (Ch, N);
     end
     else
          Result := S;
End;


HTML generated by Time2HELP
http://www.time2help.com