Procedure TForm1. Button1Click (Sender: TObject);
Var f: TextFile; S: a string; SPos, ePos: Integer; SL: TStringList;
The begin
SL:=TStringList. Create;
AssignFile (f, 'a. og);
Reset (f);
While not eof (f) do the begin
Readln (f, s);//assigned to S,
If Pos (' TXN='s) & gt; 0 then the begin/line/find the specified string
SPos:=Pos ('=', s);//to find the location of the "="
EPos:=Pos ('; 's);//search for ";" The location of the
SL. The Add (Copy (sPos + 1 s, ePos - sPos - 1));//contains ";" To obtain ":" ";" The string
S1:=(sL) Text);
SL. The Clear;
Showmessage (s1);
end;
If Pos (' TXP='s) & gt; 0 then the begin/line/find the specified string
SPos:=Pos ('=', s);//to find the location of the "="
EPos:=Pos ('; 's);//search for ";" The location of the
SL. The Add (Copy (sPos + 1 s, ePos - sPos - 1));//contains ";" To obtain ":" ";" The string
S2:=(sL) Text);
SL. The Clear;
Showmessage (s2);
end;
If Pos (' "success" : true, 's) & gt; 0 then the begin
Showmessage (' found ');
end;
end;
FreeAndNil (sL);
Closefile (f);
end;
Using the key event without the code file search is normal, if the file contains the code is not normal for a great god, attached with the code file,
http://182.129.243.99:8000/aaa/a.log
CodePudding user response:
Procedure TForm1. Button2Click (Sender: TObject);
Var
SL: TStringList;
I: string;
The begin
SL:=TStringList. Create;
SL. LoadFromFile (' a. og, TEncoding UTF8);
If SL. IndexOf (TXN '=') & gt; 0 then
The begin
Showmessage (" ok ");
end;
SL. Free;
end;
Also tried using this method, change the encoding UTF8, complains, no reflection, ANSI, and don't know what method should be used to read the file,,
CodePudding user response:
procedure TForm1. Button2Click (Sender: TObject);
Var
SL: TStringList;
I: Integer;
The begin
SL:=TStringList. Create;
SL. LoadFromFile (' a. og);
For I:=0 to SL. Do the Count - 1
The begin
If Pos (' TXN='SL [I]) & lt;> 0 then
Showmessage (" ok ");
end;
SL. Free;
end;
CodePudding user response:
Upstairs eldest brother, can you tried, but I am not for real LOG file, the program will card dead!!!!!! ?? There no response, such as I now the size of the LOG file is 1.5 M, above my a. og I have to update into the LOG file for originally, I in you on the basis of the changes you see if there are any incorrect place, now running is not normal,
Procedure TForm1. Button1Click (Sender: TObject);
Var
SL: TStringList;
SPos, ePos, I: Integer;
The begin
SL:=TStringList. Create;
SL. LoadFromFile (' a. og);
For I:=0 to sL. Do the begin the Count - 1
If Pos (' TXN='sL [I]) & gt; 0 then the begin/line/find the specified string
Showmessage (sL [I]);
SPos:=Pos ('='sL [I]);//to find the location of the "="
EPos:=Pos ('; 'sL [I]);//search for ";" The location of the
SL. The Add (Copy (sL [I], sPos + 1, ePos - sPos - 1));//contains ";" To obtain ":" ";" The string
S1:=sL. The Text;
SL. The Clear;
Showmessage (s1);
end;
end;
SL. Free;
end;
Mainly to find TXN=are extracted from the back of the string and assign a value to a global variable S1..
CodePudding user response:
Remind the building Lord, since there is the so-called gibberish, then there may be 0 x00, in DELPHI, and disposed of in accordance with the way of the string, will encounter this as the end of the string, lead to the back of the content is not processing, so, I suggest that the original poster with binary search replacement, is also very simple, the content read into a stream, and then use CompareMem comparison,CodePudding user response:
Procedure TForm1. Button2Click (Sender: TObject);Var
SL: TStringList;
I: string;
The begin
SL:=TStringList. Create;
SL. LoadFromFile (' a. og, TEncoding UTF8);
If SL. IndexOf (TXN '=') & gt; 0 then
The begin
Showmessage (" ok ");
end;
SL. Free;
end;
CodePudding user response:
Your file? Sent up!CodePudding user response:
//not stuck, very fast//find TXN value only, other analogy
The unit Unit1;
Interface
USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants,
System. The Classes, the Vcl. Graphics, Vcl. Controls, Vcl. Forms, Vcl. Dialogs,
The Vcl. StdCtrls;
Type
TForm1=class (TForm)
For: TButton;
Procedure Button1Click (Sender: TObject);
Private
The function FindPos (const StrBuf, FileBuf: TBytes; BeginNo: Integer=0) : Integer;
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
The function TForm1. FindPos (const StrBuf, FileBuf: TBytes; BeginNo: Integer) : Integer;
Var
I: Integer;
The begin
Result:=1;
For I:=BeginNo to Length (FileBuf) - Length (StrBuf) do
The begin
If CompareMem (@ StrBuf [0], @ FileBuf [I], Length (StrBuf)) then
The begin
Result:=I;
Break;
end;
end;
end;
Procedure TForm1. Button1Click (Sender: TObject);
Var
Stream: TFileStream;
Encoding: TEncoding;
I, Pos1, Pos2, DataLen: Integer;
StrBuf, FileBuf RstBuf: TBytes;
The begin
Encoding:=TEncoding. Ansi;//if the file is encoded as Unicode, Unicode
it TEncoding instead.
Stream:=TFileStream. Create (' a. og, fmOpenRead);
SetLength (FileBuf, Stream. Size);
Stream. ReadBuffer (FileBuf, Stream. Size);
Stream. Free;
StrBuf:=Encoding GetBytes (' TXN);
Pos1:=FindPos (StrBuf, FileBuf);
If Pos1 & gt;=0 then
The begin
Pos1:=Pos1 + Length (StrBuf);
StrBuf:=Encoding GetBytes ('=');
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull