Usage of StreamReader like C++ >>

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am migrating a program from C++ to C# and have encountered a difficulty in
reading the data files. For example, when the data file looks like the
following:

75000 77270
7900 8030

*Note that the spacing between the numbers are tabs, and there is a return
between subsiquent lines.

The C++ code to read this is the following:

ifstream InputFile("ActInput.inp");
InputFile >> SpadaVol[0] >> SpadaMaxVol;
InputFile >> ChapVol[0] >> ChapMaxVol;

I understand the use of StreamReader to read a line, as there are many posts
and instructions on that topic, but I am unable to find a methodology to read
tab delimited or space seperated files (with a variable or consistent number
of spaces). Most annoyingly, there is a broken link in a post to a csv (and
apparently tab delimited) file reader.
 
Can you be more specific on where the broken link was pointing to? It's
possible that it's to a site of mine, or that I would know what was on
it. Also, I sell a csv parser that would fit the bill,
http://www.csvreader.com . My methodology is a complex one based on
speed and a state machine that handles text qualifiers, and escaping
within the data if for instance there's a tab inside one of your cells.
The simple answer to your question is to do ReadLine to read in the
file, and use Split to split based on each occurance of a tab, but like
I said, this method wouldn't handle proper delimited files such as csv.
 
Back
Top