Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi txt datei filtern (https://www.delphipraxis.net/21020-txt-datei-filtern.html)

Christian18 26. Apr 2004 20:47


txt datei filtern
 
Hallo,

ich habe eine log datei und wollte diese auswerten. es ist eine textdatei und die wollte ich in ein Grid einlesen. wie mache ich das???

217.184.141.217 - - [22/Apr/2004:17:09:55 +0200] "GET / HTTP/1.1" 200 636 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"

so sehen die einträge aus.

ich wollte sie so haben

feld 1 im Grid: 217.184.141.217

feld 2 im Grid: 22/Apr/2004:17:09:55 +0200

feld 3 im Grid: "GET / HTTP/1.1" 200 636 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"

XeRo 26. Apr 2004 21:05

Re: txt datei filtern
 
Also wenn die zeilen immer gleich lang sind, dann würd ich erstmal ne zeile mittels string einlesen und dann mittels copy aufteilen... :gruebel:

SirThornberry 26. Apr 2004 21:08

Re: txt datei filtern
 
am besten mit "copy" und "posex"
Delphi-Quellcode:
var LStartpos, LEndepos: Integer;
    LPart1, LPart2, LPart3, Lzeile: String;
begin
  Lzeile := '217.184.141.217 - - [22/Apr/2004:17:09:55 +0200] "GET / HTTP/1.1" 200 636 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"';

  LStartpos := 1;
  LEndepos := PosEx(' - - [', LZeile);
  LPart1 := copy(LZeile, LStartpos, LEndepos - 1);

  LStartpos := posEx(' - - [', LZeile, LEndepos) + 6;
  LEndepos := posEx('] "', LZeile, LStartpos);
  LPart2 := copy(LZeile, LStartpos, LEndepos - LStartpos);

  LStartpos := LEndepos + 3;
  LEndepos := length(LZeile);
  LPart3 := copy(LZeile, LStartpos, LEndepos - LStartpos);

XeRo 26. Apr 2004 21:25

Re: txt datei filtern
 
Na toll, ich plag mich da ab, und versuch auf eine lösung zu kommen, dabei hat sie SirThornberry bereits gebracht.

meine sah so aus...

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
const
   aha='217.184.141.217 - - [22/Apr/2004:17:09:55 +0200] "GET / HTTP/1.1" 200 636 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"';

var
 a,b:Integer;
 c,d:Boolean;

begin
For a:=1 to Length(aha) do
 begin
  if (aha[a]=' ')and(c=False) then
   begin
    StringGrid1.Cells[0,0]:=Copy(aha,0,a);
    c:=True;
   end;
  if aha[a]='[' then b:=a;
  if aha[a]=']' then StringGrid1.Cells[1,0]:=Copy(aha,b,a);
  if (aha[a]='"')and(d=False) then
   begin
    StringGrid1.Cells[2,0]:=Copy(aha,a,Length(aha));
    d:=True;
   end;
 end;
end;

Einen Versuch wars wert...


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:57 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz