...left/right-pad strings with a character?
|
Autor:
Loïs Bégué |
[ Print tip
] | | |
function LeftPad(S: string; Ch: Char; Len: Integer): string;
var
RestLen: Integer;
begin
Result := S;
RestLen := Len - Length(s);
if RestLen < 1 then Exit;
Result := S + StringOfChar(Ch, RestLen);
end;
function RightPad(S: string; Ch: Char; Len: Integer): string;
var
RestLen: Integer;
begin
Result := S;
RestLen := Len - Length(s);
if RestLen < 1 then Exit;
Result := StringOfChar(Ch, RestLen) + S;
end;
{Beispiel / Example}
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := Rightpad(Edit2.Text, '-', 30);
end;
|