Fórum RPAD/LPAD em Delphi (era: Gostaria de saber se...) #346477
22/09/2007
0
tenho uma string. e quero que essa string tenha tamanho x. Caso não tenha esse tamanho completa-se com espaços vazios por exemplo. Estilo a função LPAD e RPAD do Oracle onde:
LPAD(STRING,TAM,CARACTER_A_COMPLETAR) preenche com caracter_a_completar depois de string.
RPAD(STRING,TAM,CARACTER_A_COMPLETAR) preenche com caracter_a_completar antes de string.
Até mais.
Iniciante2007
Curtir tópico
+ 0Posts
24/09/2007
Paulo
Ve se isto te ajuda. Na parte str := str + ´´, você coloca o quiser, neste caso tem espaço vazio, mas pode ser ´*´, ´@´, e etc....
Gostei + 0
24/09/2007
Alcantarus
Em minhas aplicacoes eu uso essa:
// Funcao TAM function TfmPrincipal.Tam ( sField : string; iLength : integer; sChar: string ) : string; begin while Length(sField) < iLength do begin sField := sField + sChar; end; Result := Copy(sField, 1, iLength); end;
Abracos,
Alcantarus.
Gostei + 0
11/10/2007
Khundalini
function RPad(const s: String; Pad: Integer): String;
begin
if (Trim(s) = EmptyStr) or (Pad = 0) then
Result := EmptyStr
else
Result := Format(´¬-*.*s´, [Pad, Pad, s]);
end;
function LPad(const s: String; Pad: Integer): String;
begin
if (Trim(s) = EmptyStr) or (Pad = 0) then
Result := EmptyStr
else
Result := Format(´¬*.*s´, [Pad, Pad, s]);
end;
Sds.,
Rubem Rocha
Manaus, AM
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)