Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 10-05-2001, 02:27 AM
rzinburg rzinburg is offline
Junior Member
 
Join Date: Mar 2001
Posts: 18
Default Correct reading of ascii files

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.
Reply With Quote
  #2  
Old 10-05-2001, 02:48 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Correct reading of ascii files

Do you think you could post an example?
Reply With Quote
  #3  
Old 10-08-2001, 01:42 AM
rzinburg rzinburg is offline
Junior Member
 
Join Date: Mar 2001
Posts: 18
Default RE: Correct reading of ascii files: Example

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.
Reply With Quote
  #4  
Old 10-05-2001, 02:50 AM
PoseFant PoseFant is offline
Senior Member
 
Join Date: Jan 2001
Posts: 1,002
Default RE: Correct reading of ascii files

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.