Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 17.02.07 22:32 
moin :)

und zwar hab ich ein prob ich will aus der log nur die client ip raus filtern
da die trenn zeichen immer ; sind und die länge des strings variiert weiß ich
nicht wie ich das lösen kann.


log beispiel:
13/02/2007 - 12:29:54;127.0.0.1;sdmfjsdf@meinedomain.com;192.168.123.129;ClearText;;;;;;;;;
13/02/2007 - 12:29:54;127.0.0.1;este@meinedomain.com;192.168.123.5;ClearText;;;;;;;;;
13/02/2007 - 12:29:54;127.0.0.1;rgjnrth@meinedomain.com;192.168.123.10;ClearText;;;;;;;;;
13/02/2007 - 12:29:54;127.0.0.1;alba@meinedomain.com;192.168.123.84;ClearText;;;;;;;;;
13/02/2007 - 12:30:00;127.0.0.1;aballesteros@meinedomain.com;192.168.123.95;ClearText;;;;;;;;;
13/02/2007 - 12:30:00;127.0.0.1;storres@meinedomain.com;192.168.123.155;ClearText;;;;;;;;;


output: nur die letzte ip (192.168.123.129) bei zeile 1 zbsp.


danke für eure hilfe
mfg sauger chris
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 17.02.07 22:44 
Schau Dir mal die TStringList und die Eigenschaften CommaText und Delimiter \DelimitedText an ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 17.02.07 22:57 
Moin!

Du kannst das auch mit Regular-Expressions machen. Hier ist ein Beispiel, wie man sowas macht (müßtest du halt immer nur auf eine Log-Zeile ansetzen). ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 18.02.07 02:05 
Meinst du nicht, dass RegEx etwas überzogen ist? ;)

CommaText dürfte schon das einfachste sein. Oder such mal nach Suche in: Delphi-Forum EXPLODE.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: So 18.02.07 08:59 
ok das mit dem string umwandeln passt jetzt so weit
hab den code hier verwendet ):

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray;
var
  SepLen: Integer;
  F, P: PChar;
  ALen, Index: Integer;
begin
  SetLength(Result, 0);
  if (S = '') or (Limit < 0) then Exit;
  if Separator = '' then
  begin
    SetLength(Result, 1);
    Result[0] := S;
    Exit;
  end;
  SepLen := Length(Separator);
  ALen := Limit;
  SetLength(Result, ALen);


  Index := 0;
  P := PChar(S);
  while P^ <> #0 do
  begin
    F := P;
    P := StrPos(P, PChar(Separator));
    if (P = nil) or ((Limit > 0) and (Index = Limit - 1)) then P := StrEnd(F);
    if Index >= ALen then
    begin
      Inc(ALen, 5); // mehrere auf einmal um schneller arbeiten zu können
      SetLength(Result, ALen);
    end;
    SetString(Result[Index], F, P - F);
    Inc(Index);
    if P^ <> #0 then Inc(P, SepLen);
  end;
  if Index < ALen then SetLength(Result, Index); // wirkliche Länge festlegen
end;



funz alle prima nur ein prob hab ich noch er wandelt nur die erste zeile um :(

normal solte es ja mit der procedure klappen aber nix is
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  exploded: TStringDynArray;
  i : integer;
begin
for i := 0 to memo1.Lines.count - 1 do
  exploded := explode(';', memo1.Lines.text);
  memo2.Lines.Add(exploded[3]);                // nach dem dritten ; string in memo2 adden
end;


oder lieg ich falsch


danke schon mal für eure hilfe =)
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 18.02.07 09:52 
wie wär's mit 'ner kleinen for schleife? einfach 3 mal ';' zählen und ab dort den start von copy setzen und schon kannst du es dir prima rauskopieren ;-) . (da brauchte nicht mit kanonen auf spatzen zu zielen ;-).) die erste und letzte zeile kannst ja auch prima über 'ne IF abfrage oder die schleifenbedingung speziell behandeln. <HTH>


Zuletzt bearbeitet von Grenzgaenger am So 18.02.07 09:53, insgesamt 1-mal bearbeitet
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: So 18.02.07 09:53 
ups hatte n kleinen fehler :)

so muß das aus sehen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var 
  exploded: TStringDynArray; 
  i : integer; 
begin 
for i := 0 to memo1.Lines.count - 1 do 
  exploded := explode(';', memo1.Lines.strings[i]);   // zeile die gecheckt wird :) 
  memo2.Lines.Add(exploded[3]);                // nach dem dritten ; string in memo2 adden 
end;



so passts :=)

danke ;)
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 18.02.07 12:43 
user profile iconSauger Chris hat folgendes geschrieben:
so muß das aus sehen

Nö ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var 
  exploded: TStringDynArray; 
  i : integer; 
begin 
  for i := 0 to memo1.Lines.count - 1 do
  begin
    exploded := explode(';', memo1.Lines.strings[i]);   // zeile die gecheckt wird :) 
    memo2.Lines.Add(exploded[3]);                // nach dem dritten ; string in memo2 adden 
  end;
end;

Das begin/end hat gefehlt ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
highlander7878
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Fr 09.03.07 19:29 
Hallo,

habe auch ein ähnliches Problem , möchte aus einem String etwas rausfiltern und zwar das das in der Klammer " ( ) " steht.
In dem Beispiel soll das Wort " text " in einer Memo ausgegeben werden.
Der Inhalt steht immer in der Klammer , aber nicht immer an der selben Stelle im String

Wie mache ich das am einfachsten ?


Log Beispiel:

09.03.2007-192.168.0.1 127.0.0.1 SERVER ( test )


Danke für jede Info

Mfg
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 10.03.07 23:03 
Moin!

Schau mal nach den Befehlen Pos()und Copy()in der Delphi-Online-Hilfe, damit kommst du weiter. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.