was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

29 Visitors Online


 
...zeilenweise auslesen und ändern einer Textdatei?
Autor: Sebastian Derdulla
Homepage: http://move.to/sebspace
[ Tip ausdrucken ]  

Tip Bewertung (17):  
     


procedure TForm1.Button1Click(Sender: TObject);
var
  
i, z: Integer;
  f: TextFile;
  t: string;
  Data: array of string;
begin
  if 
OpenDialog1.Execute then
  begin
    
//Read line by line in to the array data
    
AssignFile(f, OpenDialog1.FileName);
    Reset(f);
    z := 0;
    SetLength(Data, 0);
    //Repeat for each line until end of file
    
repeat
      
Inc(z);
      readln(f, t);
      SetLength(Data, Length(Data) + Length(t));
      Data[z] := t;
    until EOF(f);

    SetLength(Data, Length(Data) + 3 * z);
    //Add to each line the line number
    
for i := 1 to do Data[i] := IntToStr(i) + ' ' + Data[i];
    SetLength(Data, Length(Data) + 2);
    //Add a carriage return and line feed
    
Data[1] := Data[1] + #13 + #10;
    i       := Length(Data[5]);
    Data[5] := '';
    SetLength(Data, Length(Data) - i);
    //create a new textfile with the new data
    
AssignFile(f, OpenDialog1.FileName + '2');
    ReWrite(f);
    //write all lines
    
for i := 1 to do writeln(f, Data[i]);
    //save file and close it
    
CloseFile(f);
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners