tirar ponto e traço de uma string?

15/05/2003

0

[b:1221ebccd4] Como faço para tirar ponto(.) e traço (-) de uma string no caso estou convertendo uma base de dados.

ex .: 123456-96
123.123.12-6

gostaria de tirar os tarços e os pontos da string


ex .: 12345696
123123126[/b:1221ebccd4]


Guigao

Guigao

Responder

Posts

15/05/2003

Hatrix

tente usar isso:
procedure TForm1.Button2Click(Sender: TObject);
var i,j : integer;
texto:string;
textofinal:string;
begin
texto := edit1.text;
textofinal := ´´;
for i:=1 to length(texto) do
begin
if not((copy(texto,i,1) = ´-´)or(copy(texto,i,1) = ´.´)) then
begin
textofinal := textofinal+copy(texto,i,1);
end;
end;
label1.caption := textofinal;
end;


Responder

15/05/2003

4_olho

Crie uma string auxiliar.
Percorra a string original, caracter a caracter;
Veja se o caracter está em [0..9];
Em caso afirmativo, adicione este caracter na string auxiliar;
Em caso negativo, vá para o próximo
No final se desfaça da string original e renomeie a auxiliar

Desculpe não lhe dar o peixe ...


Responder

15/05/2003

By Alemão

procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
Edit2.Text := ´´;
for i:=1 to Length(Edit1.Text) do begin
if (copy(Edit1.Text,i,1) = ´.´) or (copy(Edit1.Text,i,1) = ´-´) then
Edit2.Text := Edit2.Text
else Edit2.Text := Edit2.Text + (copy(Edit1.Text,i,1));
end;
end;


Responder

15/05/2003

E_gama

procedure TForm1.Button1Click(Sender: TObject);
const NaoCopiar = ´-.,=+´; // Os caracteres que serão excluídos
var I: Integer;
    S: string;


begin
  Edit2.Text := ´´;
  S          := Edit1.Text;
  for I := 1 to Length(S) do
   begin
     if Pos(S[I], NaoCopiar) = 0 then
        Edit2.Text := Edit2.Text + S[I];
   end;
end;



Responder

17/05/2003

Dcport

Também quero participar do concurso... :)

function KeepOnlyDigits(var Texto: string): string;
var
  i, j: Integer;

begin
  j := 0;
  for i := 1 to Length(Texto) do
    if Texto[i] in [´0´..´9´] then
    begin
      Inc(j);
      Texto[j] := Texto[i];
    end;
  SetLength(Texto, j);
  Result := Texto;
end;



-- dcport


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar