How to get each line from file to array

 

Hello, i need a very simple code to get data from file. in the file have some data in lines.

Example: 

2021.01.01 01:00:00
2022.01.02 01:00:00
2023.01.03 01:00:00
2024.01.04 01:00:00
2025.01.05 01:00:00

i am using this method with manual.

string list[] = {"2021.01.01 01:00", "2022.02.02 01:00", "2023.01.06 06:00", "2024.01.08 10:00"};
   
   
   
   int maxarray = ArraySize(list);
   int shift = 0;
        
   if(shift<maxarray)
     {
      string value = (string)list[shift];
      time = (string) list[shift]; //
     }

so now i want to get my file time list in to array veriable list[].

 
Ali Raza: , i need a very simple code to get data from file
  1. Everything you posted is irrevalent. Nothing to do with reading from a file.

  2. Perhaps you should read the manual. FileOpen and FileReadDatetime
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help (2017)

 

I am tried this code to get file arraysize but the value is always =0 . 

int arr[];  string Text;
         string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
         int FileHandle= FileOpen("DataFile.txt", FILE_CSV|FILE_READ|FILE_WRITE);
         if(FileHandle!=INVALID_HANDLE)
           {
           FileReadArray(FileHandle,arr);
            int size=ArraySize(arr);
            
            for(int i=0;i<size;i++)
            Text = (string) FileReadString(FileHandle,arr[i]);
            PrintFormat("Total Arrays in File: ",Text);
            FileClose(FileHandle);
            Print("File Array Size",size); // its always says 0 but in the file have data.
           }


it is not getting file string & not the arraysize Arraysize means how many lines are present in my DataFile.txt

i just want to get all lines from my file in array[] 

such as 

string result[] = {"line_1","Line_2","Line_3","Line_4"};

the result array get Line_1,Line_2 etc from the file.

 
Ali Raza #: I am tried this code

You need to read the documentation. Read Array only works with binary files.