很简单,首先找出最长的哪 一串,再将其它的串前填充与最大长度的差的一半的空格
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure mid(sList:TStrings);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.mid(sList: TStrings);
Var
iMaxLength,i,j:Integer;
sTemp:String;
begin
iMaxLength := 0;
for i := 0 to sList.Count -1 do
if Length(TrimLeft(TrimRight(sList.Strings))) > iMaxLength then
iMaxLength := Length(TrimLeft(TrimRight(sList.Strings)));
for i := 0 to sList.Count -1 do
Begin
sTemp := '';
for j := 1 to (iMaxLength - Length(TrimLeft(TrimRight(sList.Strings)))) div 2 do
sTemp := sTemp + ' ';
sList.Strings := sTemp + TrimLeft(TrimRight(sList.Strings));
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
mid(memo1.Lines);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Font.Charset := GB2312_CHARSET;
memo1.Font.Name := 'Fixedsys';
end;
end.