I found it is much easier to read the file completely into one string variable and then split the file by '\n' into an array of lines to walk through:
int size = (int)FileSize(file_handle); string str = FileReadString(file_handle,size); string arrFile[]; int nLines = StringSplit(str,'\n',arrFile); for(int i=0; i<nLines; i++){ ... }
Thanks for the reply Gooly, I've got it to work and I must admit, it is less code.
But arrays are something I'll need to dig in some more...
But arrays are something I'll need to dig in some more...
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Greetings fellow coders and traders.
I've just recently begun scripting in MQL4 and I find it rather challenging but easy to grasp and understand. Although some steps do give me trouble and I wonder if you'd be able to help me with that.
I am trying to read from a .TXT file with the name of Output.txt that currently contains four lines of code.
The insides of this file look like this:
There are exactly 20 of those little dashes on line three. I've been playing around with some basic structures of ReadFile, and I've mashed up something like this.
Reffer to the comments inside the code for the current operation.
Now what I would like to do is display the content from only the fourth line, as I deem it most important. One way to solving this I find in this:
But I am looking for a way which would read the fourth line without the need for another IF statement. Maybe by adding some int value to StringSize or INT_VALUE?
Or is there a completely different approach that I'm not considering.
Thank you for reading,
Lovro Mirnik