![]() |
|
|
|
#1
|
|||
|
|||
|
I have ascii files which have stored data in form of rows and columns. The first row usually contains a date.
The problem is that I don't know the format of the date (date format and date separator) and I don't know the separator of the data (comma or space or whatever character). Before reading the file I could ask the user to check it and to specify the correct date format, date separator and data separator but it would be much nicer when the program can find out these things by itself and read the data correctly. How can this be done? Are there routines already available which are reading such an ascii file correctly "without knowing" these format issues? Thanks for your help. |
|
#2
|
|||
|
|||
|
Do you think you could post an example?
|
|
#3
|
|||
|
|||
|
This is an example of such an ASCii-file:
1/31/2000,98.1875,94.875,97.875,36597100 1/24/2000,105.688,97.25,98.25,147333000 1/18/2000,116.5,103.25,103.75,151908900 1/10/2000,114.25,101.5,112.25,157400000 In this case the date format is mm/dd/yyyy and as date separator / is used. To separate the data a , is used. But easily you can imagine a space as data separator and another date format and date separator e.g.: 31.2.2000 98.1875 94.875,97.875 36597100 etc. |
|
#4
|
|||
|
|||
|
Yes and no ...
There are several ways to read an ASCII file and buffer it in your Application for further analysis. These may be : - LoadFromFile(); LoadFromFile() is a method in the most common text controls. It is also possible to load data into a memory stream. - ReadLn(); With AssignFile(); you can use ReadLn(); to read one and one line. - BlockRead(); With BlockRead you read the data on byte level. And there is certainly more methods. --- Analysis : When you have the data in your preffered buffer you now have to analyze it in order to separate the different fields,columns,parts of text with interest. Usually the bulks are separated with something called a delimiter, ea. delimiter is a comma, a dot, a space or whatever the process choose when dumping the raw data. There are several routines to handle string search with variable delimiters, just search on this forum or other Delphi forums. --- Working with data : When you have separated the data due to the delimiters you now have to deal with it according to what it is. Normally the data records in one spesific column has the same format. --- Your question : I recommend you to take a visit to this page : http://www.merlyn.demon.co.uk/frames-1.htm Select the Date Time section and Pascal. However, they may be difficult to understand, but then ... ask for the specific case and we will help you out )I reckon this is the best documentation in the world for dealing with date/time in a programmers environment. These pages also has several programming issues that are VERY interesting to read ... Regards /Filip |
![]() |
| Thread Tools | |
| Display Modes | |
|
|