Buscar

Retira o espaço em branco no inicio ou fim de uma string (funciona)

Código

Function tira_espaco(x:String):String; Export;
var
quant: integer;
x_ini, x_fim: string;
Begin
quant:= Length(x);
x_ini:= copy(x,0,1);
x_fim:= copy(x,quant,1);

 if (x_ini = ' ') and (x_fim = ' ') then
   begin
    delete(x,1,1);
    delete(x,(quant-1),1);
   end;
 if (x_ini = ' ') and (x_fim <> ' ') then
    delete(x,1,1);

 if (x_ini <> ' ') and (x_fim = ' ') then
    delete(x,quant,1);

Result:=x;
end;


// exemplo de funcionamento

procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.text:= (tira_espaco(edit1.text));
end;

 

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Object pascal
Adicionada dia: 14/05/07
Por: Tarcisio Fernandes
Visualizada: 10747 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009