固定字符串的长度为10 var s:String; i,j:Integer; begin s:='1321323'; i:=length(s); if i<10 then begin for j:=1 to 10-i do begin s:=s+'0'; end; Caption:=s; end; end;
for i:= 1 to 40-Length(s) do begin s := ' ' + s; end;
function FormatStr2(i: integer): string; //格式字符串 begin Result:=Format('%40d',[i]); end; procedure TForm1.Button1Click(Sender: TObject); begin edit2.Text:=FormatStr2(StrToInt(edit1.text)); //调用 end;
var
s:String;
i,j:Integer;
begin
s:='1321323';
i:=length(s);
if i<10 then
begin
for j:=1 to 10-i do
begin
s:=s+'0';
end;
Caption:=s;
end;
end;
Memo1.Lines.Add(Format('%-8s%-20s%-20s', ['300', '213.10563985152', '16427.8710195534']));
Memo1.Lines.Add(Format('%-8s%-20s%-20s', ['1000', '220.335354', '19433.5782228']));右对齐
Memo1.Lines.Add(Format('%8d%20.10f%20.10f', [300, 213.10563985152, 16427.8710195534]));
Memo1.Lines.Add(Format('%8d%20.10f%20.10f', [1000, 220.335354, 19433.5782228]));在视觉上可能不一样长、但調整「Memo1.Font」的字体、字型等、可让视觉改变成一样长。
s := ' ' + s;
end;
begin
Result:=Format('%40d',[i]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text:=FormatStr2(StrToInt(edit1.text)); //调用
end;
洒家教你们一个简单方法
Modi:=copy(origin+' ',1,40);
加的是四十个空格,不知道csdn的贴子会不会省去。
意思就是在尾巴加四十个空格,然后取前40位。