j:=Length(s); for i:=1 to (10-j) do begin s:=s+' '; end;
copy('12345'+' ',1,10)
function AddSpace(AString: string; ALength: integer): string; var i: integer; begin if Length(AString) < 10 then begin for i := Length(AString) to 9 do Result := AString + ' '; end else Result := AString; end;
再修改一下: function AddSpace(AString: string; ALength: integer): string; var i: integer; begin if Length(AString) < ALength then begin for i := Length(AString) to ALength - 1 do Result := AString + ' '; end else Result := AString; end; 如果你最大长度为:10则带参数ALength为10;
又跟 jinjazz 学了一招!
还是 jinjazz(近身剪(N-P攻略)) 厉害些。
//虽然已结还是要说一下Format的用法 var S: string; begin S := '12345'; S := Format('%-10s', [S]); end;
for i:=1 to (10-j) do
begin
s:=s+' ';
end;
var
i: integer;
begin
if Length(AString) < 10 then
begin
for i := Length(AString) to 9 do
Result := AString + ' ';
end
else Result := AString;
end;
function AddSpace(AString: string; ALength: integer): string;
var
i: integer;
begin
if Length(AString) < ALength then
begin
for i := Length(AString) to ALength - 1 do
Result := AString + ' ';
end
else Result := AString;
end;
如果你最大长度为:10则带参数ALength为10;
var
S: string;
begin
S := '12345';
S := Format('%-10s', [S]);
end;