I'm total begginer so let's begin
for example i want to read specific line from a txt file, how do i do that!?!?!
for example Code:
AssignFile(Somefile, 'somefile.txt');
Reset(Somefile);
// how to read line??? //
Closefile(somefile);
i was trying to findd something on internet, maybe there were correct answers but i didn't understand them... so if anyone knows, HELP ME and with some explanations would be better...
Comments
: for example i want to read specific line from a txt file, how do i do that!?!?!
: for example Code:
:
: AssignFile(Somefile, 'somefile.txt');
: Reset(Somefile);
: // how to read line??? //
: Closefile(somefile);
:
: i was trying to findd something on internet, maybe there were correct answers but i didn't understand them... so if anyone knows, HELP ME and with some explanations would be better...
:
You can use ReadLn() to read a line from a text file. The first ReadLn() reads the first line, second ReadLn() the second, etc.
Alternatively you can create a TStringList object and call its LoadFromFile(). This will store the entire fill into the object. Then you can use the Strings[] property to get the line you want.
: : for example i want to read specific line from a txt file, how do i do that!?!?!
: : for example Code:
: :
: : AssignFile(Somefile, 'somefile.txt');
: : Reset(Somefile);
: : // how to read line??? //
: : Closefile(somefile);
: :
: : i was trying to findd something on internet, maybe there were correct answers but i didn't understand them... so if anyone knows, HELP ME and with some explanations would be better...
: :
: You can use ReadLn() to read a line from a text file. The first ReadLn() reads the first line, second ReadLn() the second, etc.
: Alternatively you can create a TStringList object and call its LoadFromFile(). This will store the entire fill into the object. Then you can use the Strings[] property to get the line you want.
:
Thank you will try it
AsignFile...
...
repeat
var2:= var2+1;
readln(file, var);
until var1 = var2;
...
that's how it was solved!
: didn't understand how to use TStringList, so i wrote little code:
: AsignFile...
: ...
: repeat
: var2:= var2+1;
: readln(file, var);
: until var1 = var2;
: ...
: that's how it was solved!
:
:
Here is a slightly better code, which also checks if the file is not empty:
[code]
while not eof(file) do
begin
var2 := var2+1
readln(file, var);
if var1 = var2 then Break;
end;
[/code]
When using the TStringList variation:
[code]
var
FileContents: TStringList;
begin
FileContents := TStringList.Create;
FileContents.LoadFromFile('filename.txt');
// Use Filecontents
Line := FileContents[var2];
// until you don't need them
FileContents.Free;
end;
[/code]