Formatando Strings

Delphi

29/11/2003

Estou procurando uma forma de formatar uma string da seguinte forma:

Por Exemplo quero que uma variável receba uma string de tamanho 10,
mas se for informado uma string de 5 caractéres ele complete com espaços em branco.

Se alguém souber como, agraceço.

Marco Antonio Justo


Manjuneiro

Manjuneiro

Curtidas 0

Respostas

Afarias

Afarias

29/11/2003

function LeftPad(Str: string; Size: Integer): string;
const
PadChar = ´ ´;
begin
Result := Str;
while (Length(Result) < Size) do
Result := PadChar + Result;
end;


function RightPad(Str: string; Size: Integer): string;
const
PadChar = ´ ´;
begin
Result := Str;
while (Length(Result) < Size) do
Result := Result + PadChar;
end;



T+


GOSTEI 0
Adilsond

Adilsond

29/11/2003

Utilize a função format:

Edit2.Text := Format(´¬-20s´,[Edit1.Text]); // onde 20 é o tamnho da nova string


GOSTEI 0
POSTAR