duvida com arquivo texto
28/03/2006
0
deveria fazer um loop no texto e:
if copy(Texto.linhax, 03, 04) = copy(Texto.linhay, 03,04) then
begin
delete(linhax);
delete(linhay);
end;
conclusão:
se houver duas linhas onde os caracteres (03,04,05,06) são iguais, então deleta as duas linhas.
não sei como fazer isso, se alguem puder me ajudar !!!!!
um abraço a todos !!!!
Fabiano Góes
Posts
28/03/2006
Aroldo Zanela
Por favor, coloque um fragmento do arquivo para elaborarmos um exemplo sobre o mesmo.
29/03/2006
Fabiano Góes
01[color=red]0022[/color]000005693471558118000000009240 000687000014890270191105000000008285 010474000017403561205121000000016770 001293000018727563185102000000009950 001835000029180270252123000000008000 234252000030347483007121000000015000 000513000037007563258123000000004770 000269000058357563249102000000029955 00[color=red]0022[/color]000058437563177123000000019900 010078000077783471793123000000027080
apartir desse arquivo gostaria: em em duas ou mais linhas os caracteres da casa 3 até a casa 6 forem iguais então delete todas as linhas que estiverem nesta situação.
como exemplo, acontece o duplicidade na linha 1 e na linha 9, portanto as duas linhas deveriam ser deletadas.
29/03/2006
Ipc$
29/03/2006
Dedi
pelo que entendi vc deve pegar a primeira linha e coparar com as demais,depois pegar a segunda e comparar com as demais e assim até a penultima linha. diante disso eu faria +/- assim:
var texto1,texto2,texto3,texto4:TStringList; xl,yl:integer; linhax,linhay:string; begin texto1:=TStringList.Create; texto2:=TStringList.Create; texto3:=TStringList.Create; texto4:=TStringList.Create; texto1.LoadFromFile(´nome_do_arquivo.txt´); texto2.Text:=texto1.Text; texto3.Text:=texto1.Text; for xl := 1 to texto1.Count do begin linhax:=texto1.Strings[xl-1]; for Yl := xl+1 to texto2.Count do begin caption:=´Contados Linha x: ´+inttostr(xl)+´ LinhasY ´ + inttostr(Yl); Application.ProcessMessages; linhay:= texto2.Strings[Yl-1]; if copy(linhax,3,4) = copy(linhay,3,4)then begin if texto4.IndexOf(linhax) < 0 then texto4.Add(linhax); if texto4.IndexOf(linhay) < 0 then texto4.Add(linhay); end; end; end; texto1.Free; texto2.Free; for xl := 1 to texto4.Count do begin while (texto3.IndexOf(texto4.Strings[xl-1])>= 0) do begin texto3.Delete(texto3.IndexOf(texto4.Strings[xl-1])); end; end; texto3.SaveToFile(´nome_do_arquivo.txt´); texto3.Free; texto4.Free; ShowMessage(´Concluido...´); end;
29/03/2006
Rjun
var i, k: integer; Arquivo: TStringList; Linha: string; Flag: Boolean; begin Arquivo := TStringList.Create; try Arquivo.LoadFromFile(´C:\Teste.Txt´); i := 0; while (i < Arquivo.Count) do begin Linha := Arquivo.Strings[i]; Flag := False; k := 0; while (k < Arquivo.Count) do begin if ((i <> k) and (Copy(Linha, 3, 4) = Copy(Arquivo.Strings[k], 3, 4))) then begin Arquivo.Delete(k); Flag := True; end; Inc(k); end; if (Flag) then Arquivo.Delete(i); inc(i); end; Arquivo.SaveToFile(´C:\Teste.Txt´); finally FreeAndNil(Arquivo); end; end;
29/03/2006
Marco Salles
procedure TForm1.Button1Click(Sender: TObject); var Lista:TstringList; i,j:integer; texto:String; deletar:Boolean; begin Lista:=TstringList.Create; Lista.LoadFromFile(´c:\Teste.txt´); i:=0; j:=1; deletar:=False; while i <= Lista.Count -2 do begin texto:=Copy(lista[i],3,4); while j <= Lista.Count-1 do begin if pos(texto,Lista[j]) > 0 Then begin Lista.Delete(j); deletar:=True; end else j:=j+1; end; if Deletar Then begin Lista.Delete(i); deletar:=False; end else i:=i+1; j:=i+1; end; lista.SaveToFile(´C:\TESTE.txt´); lista.Free; showmessage(´Atualização ja processada´); end;
29/03/2006
Fabiano Góes
Desde já eu gostaria de agradecer a todos que postaram !
VALEU PESSOAL !!!!
Clique aqui para fazer login e interagir na Comunidade :)