Thanks. How do you think what kind of sorting and searching values will be useful? Could you explain, please.
Hey mate,
Great work!
Thank you for making, and sharing, this library.
I did found a logical bug in your code-
If reading a csv file without a header,
Your reader will read file as having only 1 column (well, technically 0 columns), regardless of how many columns are actually there.
DKSimplestCSVReader.mqh line 76-
if(!(aHasHeader && HeaderString == "")) { CArrayString* Row = new CArrayString; for(int i = 0; i < ArraySize(lineFields); i++) Row.Add(lineFields[i]); Rows.Add(Row); } else { HeaderString = fileLine; for(int i = 0; i < ArraySize(lineFields); i++) Columns.Add(lineFields[i], i); }
So if aHasHeader is false, the 'else' clause will never be called, and the 'Columns' HashMap will remain 0/empty.
EDIT-
Not the most elegant solution,
But just at the top of my head,
You can add something like the following, inside the 'if' clause-
if(!aHasHeader && Columns.Count() == 0) { for(int i = 0; i < ArraySize(lineFields); i++) Columns.Add("Column " + (string)(i+1), i); }
I haven't compiled the above, so it might need some syntax adaptations.
Also, it is very late, so I'm not that focused, so I can't recall if MQL accepts the sort of string concatenation I've made in the above code.
Cheers.
So if aHasHeader is false, the 'else' clause will never be called, and the 'Columns' HashMap will remain 0/empty.
I've checked the class code. For no-columns CSV files, the column list shouldn't be filled. Because, there're no headers in the file. The first line of the file contains data, but not columns name. So, parsing to fill columns list, as you suggested, is incorrect for no-header files.
Also retrieving data after reading no-header file is not possible using CSVFile.GetValue(i, "Time") method with the column name. It returns error_value in this case. But CSVFile.GetValue(i, 0) by field index works well always.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Simplest CSV file reader:
Provide simplest class to read and parse CSV file
Author: Denis Kislicyn