Page 1 of 1
How can I get contents from a local File?
Posted: 2024-06-02 15:32:16
by fulvio53s03
I have a local file "c:\commenti.txt" and I would like to extract lines containing certain words:
now
I like
this
program.
This
is the reason
why
I want to extract
this
.
How can I open the file and filter it?
Thank you!

Re: How can I get contents from a local File?
Posted: 2024-06-03 05:26:38
by antp
The TStringList class has LoadFromFile and SaveToFile functions that you can use for that:
Code: Select all
function GetLocalFile(Path: string): string;
var
File: TStringList;
FileName: string;
begin
File:= TStringList.Create;
FileName := Path;
Input('', 'File to read:', FileName);
File.LoadFromFile(FileName);
Result := File.Text;
File.Free;
end;
This is a demo function. If you want to process it line per line, you can of course directly use the TStringList object (named "File" here)
Re: How can I get contents from a local File?
Posted: 2024-06-03 18:19:57
by fulvio53s03

i'll try!