I've just finished this function and wanted to know if anyone know another way to do the same:
function findtext(archivo,Delimit1, Delimit2 :String) :String;
var
Buffer :AnsiString;
ResLength :Integer;
i :Integer;
PosDelimit :Integer;
begin
Buffer := read_file_z(archivo);
if Pos(Delimit1, Buffer) > Pos(Delimit2, Buffer) then
PosDelimit := Length(Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1))
else PosDelimit := Length(Buffer)-(Pos(Delimit2, Buffer)+Length(Delimit2));
Buffer := Copy(Buffer, (Length(Buffer)-PosDelimit), Length(Buffer));
ResLength := Pos(Delimit2, Buffer)-(Pos(Delimit1, Buffer)+Length(Delimit1));
for i := 0 to (Reslength-1) do
Result := Result+Buffer[Pos(Delimit1, Buffer)+(Length(Delimit1)+i)];
end;
The auxiliary function read_file_z is this:
function read_file_z(const FileName: String): AnsiString;
var
F: File;
DefaultFileMode: Byte;
begin
DefaultFileMode := FileMode;
try
FileMode := 0;
AssignFile(F, FileName);
{$I-}
Reset(F, 1);
{$I+}
if IoResult=0 then
try
SetLength(Result,FileSize(F));
if Length(Result)>0 then begin
{$I-}
BlockRead(F,Result[1],LENGTH(Result));
{$I+}
if IoResult<>0 then Result:='';
end;
finally
CloseFile(F);
end;
finally
FileMode := DefaultFileMode;
end;
end;
The function finds text between two tags. An example would [hi]hi world[hi] and the function will respond "hi world".
Example:
findtext('test.exe','[hi]','[hi]');
The way seek to do the function is the "uses" default.
What alternatives do I have to make the function "findtext"?