Re: Different ways of reading numbers in text files - which recommended?
- From: C <wrong.address.1@xxxxxxxxx>
- Date: Wed, 5 Aug 2009 08:29:45 -0700 (PDT)
On 5 elo, 17:31, "Dave O." <nob...@xxxxxxxxxxx> wrote:
Not enough information.
But I give you what I can - Firstly the most important aspect is how are you
reading the file, the fastest method is to read the whole file into a string
or byte array in a single pass.
Speed is not important. It is more important to do it in a simple way.
I am open to all alternatives. This is a part of my question.
Are the files fixed column or TAB separated or some other delimiter?
They are written by an old VB6 program, so they will have varying
amounts of space between the fields of varying (and unknown) sizes,
except for their type.
Assuming you've read the whole file into a single string the next step is to
use the Split function to separate the file into an array of lines, that is:
split on vbCrLf
then you need to work on each line, if it's fixed column you'd use Mid to
get each element then trim off any trailing spaces then if necessary convert
to a number.
I thought this would be an inefficient and complicated way. Sometimes
there are spaces between words in a quoted string.
If it's TAB separated then the easiest way is to use Split again, this time
with vbTab as the delimiter.
Another possibility if the fields are fixed length is to make a user defined
They are of varying sizes, because 2.000 will be written as 2. while
1.3456567 may be written as such.
Type with each element the correct length and then read the file record by
record, this will be slower to read but quicker to process each line. I've
no idea which method would be faster overall, it rather depends on too many
factors, most of which I don't have.
Speed is the least important issue. I would prefer not to spend time
and energy doing parsing of strings to convert a text file into
numbers. In Fortran, four decades ago, we used to be able to read
several numbers of varying string lengths in a single command. Now it
looks as if we are going backwards.
Thanks for your comments.
Regards
Dave O.
"C" <wrong.addres...@xxxxxxxxx> wrote in message
news:2501f03c-07f0-4f2d-94c9-61caadafba2d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
There seem to be several ways of reading files, and even more ways to
read files full of numbers (integer and floating) and strings. Could
someone advise me on which method is recommended? The file to be read
could look like this. The sequence is of course known, i.e., first two
are integers, then a floating point number, then a string, etc.
12 0 4.334E-12 effect
3.36755 "temperature at the top"
3 55
2 331
0.4326765 0.242 M
.
- Follow-Ups:
- References:
- Prev by Date: Form opening in dual monitor setup
- Next by Date: Re: Learning Visual Basic
- Previous by thread: Re: Different ways of reading numbers in text files - which recommended?
- Next by thread: Re: Different ways of reading numbers in text files - which recommended?
- Index(es):
Relevant Pages
|