Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Comparar cadenas de un txt (https://www.clubdelphi.com/foros/showthread.php?t=42290)

francisco260184 10-04-2007 23:16:59

Comparar cadenas de un txt
 
Hola, bueno ahora tengo otro problemilla :(.
Lo que intento hacer es comparar cadenasd de texto desde un archivo *.txt.
Por ejemplo, supongamos que tengo esto en un archivo txt:

M 2125 2 525.00 000 0.00
M 2125 2 109.12 000 0.00
M 2126 2 3900.00 000 0.00
M 2126 1 3900.00 000 0.00
M 2127 2 xxxx.xxx 000 0.00

Lo que intento hacer es comparar la segunda columna (2125,2125,2126,...).
para insertar una linea despues de que se termine una secuencia. Por ejemplo:

M 2125 2 525.00 000 0.00
M 2125 2 109.12 000 0.00
--------------AQUI QUIERO INSERTAR UNA LINEA--------------
M 2126 2 3900.00 000 0.00
M 2126 2 3900.00 000 0.00
M 2126 1 3900.00 000 0.00
--------------AQUI QUIERO INSERTAR UNA LINEA--------------
M 2127 2 xxxx.xxx 000 0.00
y asi sucesivamente,,, :confused::confused::confused:..

GRACIAS:::

egostar 10-04-2007 23:54:22

Aqui te dejo una rutina que te hace lo que quieres, lo hice usando dos TMemo, tú modificalo a manera de que leas el archivo de texto y sigue esa lógica.

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
Var
  linea: string;
  corte: string;
  i: integer;
begin
  Linea := Memo1.Lines.Strings[0];
  Corte := copy(linea,3,4);
  for i := 1 to memo1.Lines.Count - 1 do begin
      Linea := Memo1.Lines.Strings[i];
      if corte = copy(linea,3,4) then begin
         Memo2.Lines.Add(Linea);
      end
      else begin
             Memo2.Lines.Add('************************');
             Memo2.Lines.Add(Linea);
             Corte := copy(linea,3,4);
      end;
  end;
end;

Salud OS.


La franja horaria es GMT +2. Ahora son las 13:41:45.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi