Author Topic: Read File into an array and set a variable to the number of lines  (Read 754 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
i realize i can use Xsplit to read a file into an array (txt file), my question is how would i autoset the array size depending on how many lines on file?

say i have only 10 lines on file how would i have it detect the end of the file so that it will also return a number (the last line)

say for example my array name is ZDC and the var for the last line is EndFileNum

Code: (pascal) [Select]
for i := 1 to EndFileNum Do
how would i set EndFileNum without actually coding in the number of lines on file?

edit: title made more appropriate

edit2: would this work:
Code: (pascal) [Select]
function GetFileLineNum(file:array of string):integer;
var LineNum,i:Integer;
begin
  file:=  xsplit(readfile(file),chr(13)+chr(10));
  LineNum:=1;
  for i:= 1 to LineNum do begin
    if file[i] <> "" then begin
      LineNum:= LineNum+1;
      repeat;
    else
      Result := LineNum;
  end;
end;
« Last Edit: August 16, 2011, 01:55:51 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Read File into an array and set a variable to the number of lines
« Reply #1 on: August 16, 2011, 02:18:48 am »
iirc,

ArrayHigh(array)
GetArrayLength(array)

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Read File into an array and set a variable to the number of lines
« Reply #2 on: August 16, 2011, 02:24:16 am »
Btw, use the Explode function, it is more efficient.
http://forums.soldat.pl/index.php?topic=35698.0